67 points · by timwiseman · 17y ago · 21 comments
This is all about how cheap threads are.
Go is about twice as slow on this benchmark, and doesn't scale past 400k threads. GHC 6.12 goes to >3 million threads (limited by available ram at that point).
(I have not had enough coffee today, so I can't say how useful this setup would be. I have done threads-without-mvars for a TCP server, but my OS refused to give me any more than 300,000 pipes. Disappointing.)
Via IORefs? Or?
Performance is certainly worse with more cores. And you can end up with exponential slowdowns due to thread migration. The best strategy is to pin parts of the thread ring on each core.
Go doesn't have a good SMP scheduler, so you see that slowdown, and the GHC team have written about the solutions. See this thread: http://www.reddit.com/r/programming/comments/a4n7s/stackless...
~/development/go/dev$ time ./8.out
100000
real 0m0.632s
user 0m0.288s
sys 0m0.344s
~/install/stackless-2.6.4$ time ./python 100k.py
100000
real 0m0.350s
user 0m0.292s
sys 0m0.060s // Scheduling helpers. Sched must be locked.
static void gput(G*); // put/get on ghead/gtail
This is the comment on the lock: in the uncontended case,
* as fast as spin locks (just a few user-level instructions),
* but on the contention path they sleep in the kernel.
* a zeroed Lock is unlocked (no need to initialize each lock).
A better approach for multicore would probably be work-stealing queues.This is just a guess from someone that knows nothing about either (stackless does run in a vm, right?), so take many large grains of salt.
In short, you are comparing apples with bazookas. (Also, for a test that runs in such a short time, and running it only once, it is likely most of the time it is taken by things unrelated to what is intended.)
Thing is - it doesn't seem to have been missed from Stackless, which makes me wonder when it's needed.
The point is that Go is a compiled language designed for concurrent processing and Stackless Python is a byte-code language which also had to parse the input program as part of the timing. Even then the raw numbers put Stackless as twice as fast as Go. Assuming my machine is 4 times faster than Pike's, that still not enough to justify what I interpreted as praise for Go's concurrent processing performance.