lilydjwg / swapview-rosetta

Print swap usage per process. Implemented in various programming languages
493 stars 108 forks source link

Crystal: Add concurrent with fiber and parallel with process #146

Closed wakeofwind closed 5 years ago

wakeofwind commented 5 years ago

Tested with Crystal 0.28.0, Go 1.12.4 and Rust 1.34.2 on Arch Linux:

$ ./run_benchmark Crystal Crystal_fiber Crystal_process Go Go_goroutine Rust Rust_parallel <benchmark.toml 
Running Crystal...Ok(BenchmarkResult { topavg: 401418467, avg: 410131432, min: 390746809, max: 446683122, mdev: 12055625, count: 20 })
Running Crystal_fiber...Ok(BenchmarkResult { topavg: 398157371, avg: 408922979, min: 394555717, max: 490207292, mdev: 20431973, count: 20 })
Running Crystal_process...Ok(BenchmarkResult { topavg: 227214601, avg: 242445906, min: 223599058, max: 298057674, mdev: 22701522, count: 20 })
Running Go...Ok(BenchmarkResult { topavg: 384300686, avg: 394494455, min: 373100521, max: 413759685, mdev: 11953877, count: 20 })
Running Go_goroutine...Ok(BenchmarkResult { topavg: 167479977, avg: 172445711, min: 163489879, max: 195793858, mdev: 6916480, count: 20 })
Running Rust...Ok(BenchmarkResult { topavg: 316342107, avg: 321359432, min: 313524414, max: 331637328, mdev: 5795396, count: 20 })
Running Rust_parallel...Ok(BenchmarkResult { topavg: 148730917, avg: 151004489, min: 147642895, max: 158154243, mdev: 3417801, count: 20 })
           Rust_parallel: top:  148.73, min:  147.64, avg:  151.00, max:  158.15, mdev:    3.42, cnt:  20
            Go_goroutine: top:  167.48, min:  163.49, avg:  172.45, max:  195.79, mdev:    6.92, cnt:  20
         Crystal_process: top:  227.21, min:  223.60, avg:  242.45, max:  298.06, mdev:   22.70, cnt:  20
                    Rust: top:  316.34, min:  313.52, avg:  321.36, max:  331.64, mdev:    5.80, cnt:  20
                      Go: top:  384.30, min:  373.10, avg:  394.49, max:  413.76, mdev:   11.95, cnt:  20
           Crystal_fiber: top:  398.16, min:  394.56, avg:  408.92, max:  490.21, mdev:   20.43, cnt:  20
                 Crystal: top:  401.42, min:  390.75, avg:  410.13, max:  446.68, mdev:   12.06, cnt:  20
lilydjwg commented 5 years ago

The _fiber variant outputs an empty report. The _process variant outputs a lot of unformatted info followed by an empty report.

  PID      SWAP COMMAND
Total:       0B

Please fix it.

wakeofwind commented 5 years ago

@lilydjwg Fixed. And

lilydjwg commented 5 years ago

Parallel with process drops cmd field due to an issue which is commented in git commit message and source code.

Then drop that implementation. It doesn't work correctly besides this: a lot of processes are left behind.

wakeofwind commented 5 years ago

The original idea is to show that Crystal can do parallel jobs no less than other languages and get not bad performance without complex implementation. But it seems it's still painful at the moment. So please ignore this pull request unless there is better improvement.

wakeofwind commented 5 years ago

It doesn't work correctly besides this: a lot of processes are left behind.

Try to use msgpack to share non-value types among processes. And Will do more tests to investigate this issue.

wakeofwind commented 5 years ago

@lilydjwg It seems that the issue of

It doesn't work correctly besides this: a lot of processes are left behind.

is gone after replacing dependent shard parallel with parallel_worker.

Please check it. :-)