www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - goroutines vs vibe.d tasks

reply "Jack Applegame" <japplegame gmail.com> writes:
Just creating a bunch (10k) of sleeping (for 100 msecs) 
goroutines/tasks.

Compilers
go:     go version go1.4.2 linux/amd64
vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

Code
go:     http://pastebin.com/2zBnGBpt
vibe.d: http://pastebin.com/JkpwSe47

go version build with     "go build test.go"
vibe.d version built with "dub build --build=release test.d"

Results on my machine:

go:     168.736462ms (overhead ~ 68ms)
vibe.d: 1944ms       (overhead ~ 1844ms)

Why creating of vibe.d tasks is so slow (more then 10 times)???
Jun 30 2015
next sibling parent reply "Alex Parrill" <initrd.gz gmail.com> writes:
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
Use GDC or LDC for profiling code; the DMD optimizer isn't as good. Also, its likely that go has spent a lot more effort optimizing coroutines specifically than D has.
Jun 30 2015
parent Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Tue, 2015-06-30 at 15:20 +0000, Alex Parrill via Digitalmars-d-learn
wrote:
=20
[=E2=80=A6]
 Use GDC or LDC for profiling code; the DMD optimizer isn't as=20
 good.
Also note that gc code generation is poor compared to gccgo: always use gccgo for benchmarking. [=E2=80=A6] --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jul 02 2015
prev sibling next sibling parent "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
Don't have go installed, but for me, the timings don't change 
very much depending on compiler and optimization flags:

dub --compiler=dmd                     13346ms
dub --compiler=dmd --build=release     12348ms
dub --compiler=ldc2                    12082ms
dub --compiler=ldc2 --build=release     9351ms
Jun 30 2015
prev sibling next sibling parent reply "anonymous" <anonymous example.com> writes:
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
I think this might be a problem with vibe.d's `sleep`. Putting a `writeln("...");` there is a lot faster than `sleep`ing even the tiniest amount of time.
Jun 30 2015
parent reply "Atila Neves" <atila.neves gmail.com> writes:
On Tuesday, 30 June 2015 at 16:43:58 UTC, anonymous wrote:
 On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
I think this might be a problem with vibe.d's `sleep`. Putting a `writeln("...");` there is a lot faster than `sleep`ing even the tiniest amount of time.
Sleep will almost certainly pause and block the fiber. Vibe.d only switches between them when there's IO to be done or something else from the event loop. A better way of comparing would be to actually do something: use channels to ping-pong back between the goroutines and use vibe.d's concurrency to send messages betweeen fibers. Whatever you do, don't sleep. Atila
Jun 30 2015
parent "Jack Applegame" <japplegame gmail.com> writes:
On Tuesday, 30 June 2015 at 17:37:38 UTC, Atila Neves wrote:
 Sleep will almost certainly pause and block the fiber. Vibe.d 
 only switches between them when there's IO to be done or 
 something else from the event loop.
Sleep blocks the fiber, but not the event loop. Because it isn't core.thread.Thread.sleep, but vibe.core.core.sleep - http://vibed.org/api/vibe.core.core/sleep
Jun 30 2015
prev sibling next sibling parent "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
fwiw I have 151ms total time for go; 740 ms for ldc (O2 and singleobj), and 760ms for dmd. on an old zoostorm running 64bit arch linux. microbenchmarks may be testing many strange things, and it requires more expertise than I currently have to know where this might come from.
Jun 30 2015
prev sibling next sibling parent reply "rsw0x" <anonymous anonymous.com> writes:
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
how do they compare if you replace the sleep with yield?
Jun 30 2015
parent reply Daniel =?UTF-8?B?S296w6Fr?= <kozzi dlang.cz> writes:
Same problem still extreamly slow

On Wed, 01 Jul 2015 03:28:01 +0000
"rsw0x" <anonymous anonymous.com> wrote:

 On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
how do they compare if you replace the sleep with yield?
Jul 01 2015
parent =?windows-1252?Q?S=F6nke_Ludwig?= <sludwig rejectedsoftware.com> writes:
Am 01.07.2015 um 09:55 schrieb Daniel Kozák:
 On Wed, 01 Jul 2015 03:28:01 +0000
 "rsw0x" <anonymous anonymous.com> wrote:
 how do they compare if you replace the sleep with yield?
Same problem still extreamly slow
Hm, this is strange. I'll have to find some time to profile this. More or less all that yield() does is to call Fiber.yield() and then once processes pending events.
Jul 10 2015
prev sibling parent reply "Mathias Lang" <pro.mathias.lang gmail.com> writes:
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
In your dub.json, can you use the following: "subConfigurations": { "vibe-d": "libasync" }, "dependencies": { "vibe-d": "~>0.7.24-beta.3" }, Turns out it makes it much faster on my machine (371ms vs 1474ms). I guess it could be a good thing to investigate if we can make it the default in 0.7.25.
Jul 01 2015
next sibling parent "rsw0x" <anonymous anonymous.com> writes:
On Wednesday, 1 July 2015 at 18:09:19 UTC, Mathias Lang wrote:
 On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 [...]
In your dub.json, can you use the following: "subConfigurations": { "vibe-d": "libasync" }, "dependencies": { "vibe-d": "~>0.7.24-beta.3" }, Turns out it makes it much faster on my machine (371ms vs 1474ms). I guess it could be a good thing to investigate if we can make it the default in 0.7.25.
submit an issue on vibe.d's github, they'd probably like to know about this.
Jul 01 2015
prev sibling next sibling parent "Etienne Cimon" <etcimon gmail.com> writes:
On Wednesday, 1 July 2015 at 18:09:19 UTC, Mathias Lang wrote:
 On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) 
 goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
In your dub.json, can you use the following: "subConfigurations": { "vibe-d": "libasync" }, "dependencies": { "vibe-d": "~>0.7.24-beta.3" }, Turns out it makes it much faster on my machine (371ms vs 1474ms). I guess it could be a good thing to investigate if we can make it the default in 0.7.25.
I don't benchmark my code frequently, but that's definitely flattering :) I hope we can see a release LDC 2.067.0 soon so that I can optimize the code further. I've given up on 2.066 a while back
Jul 02 2015
prev sibling parent =?UTF-8?B?U8O2bmtlIEx1ZHdpZw==?= <sludwig rejectedsoftware.com> writes:
Am 01.07.2015 um 20:09 schrieb Mathias Lang:
 On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote:
 Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks.

 Compilers
 go:     go version go1.4.2 linux/amd64
 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23

 Code
 go:     http://pastebin.com/2zBnGBpt
 vibe.d: http://pastebin.com/JkpwSe47

 go version build with     "go build test.go"
 vibe.d version built with "dub build --build=release test.d"

 Results on my machine:

 go:     168.736462ms (overhead ~ 68ms)
 vibe.d: 1944ms       (overhead ~ 1844ms)

 Why creating of vibe.d tasks is so slow (more then 10 times)???
In your dub.json, can you use the following: "subConfigurations": { "vibe-d": "libasync" }, "dependencies": { "vibe-d": "~>0.7.24-beta.3" }, Turns out it makes it much faster on my machine (371ms vs 1474ms). I guess it could be a good thing to investigate if we can make it the default in 0.7.25.
This sounds like the event_del() + event_add() sequence that is done in the libevent driver causes this slowdown. If anyone knows of a faster way to rearm a timer for libevent that would be great. Otherwise I don't really know what to do about this (other than using a different driver). As for libasync, making it the default is maybe still a little too early, but we should definitely think about how to make it more prominent for testing (maybe even still for 0.7.24).
Jul 10 2015