3 ms·
> You can't easily spawn 10.000 OS threads. I just spawned 10.000 OS threads running separate mRuby instances in each thread on my laptop, to see if it'd cause
by vidarh 9y ago
> You can't easily spawn 10.000 OS threads.
I just spawned 10.000 OS threads running separate mRuby instances in each thread on my laptop, to see if it'd cause any problems (because I happened to have an app sitting around that spawns separate threads; note: these are not Ruby threads, mRuby does not have built in threading). None at all. So yes, you can. I didn't check how much memory it'd take, however, or attempt to measure overheads in any way, so I'm not saying there aren't potential issues with it.
- jashmatthews 9y agoSimply using 1,000+ OS threads is often very close to as efficient as using coroutines or an event loop: https://www.slideshare.net/e456/tyma-paulmultithreaded1 https://www.slideshare.net/e456/tyma-paulmultithreaded1
- zzzcpan 9y agoIf your event loop is as slow as 1000+ coroutines or OS threads, you are doing it very very wrong.
- jashmatthews 9y agoAFAIK the main benefit to coroutines is getting to manually manage tiny stacks. For example, in Go, they mark a goroutine's stack as "hasn't executed since the last time we marked", which makes GC with thousands of threads a lot faster.
- arghwhat 9y ago[Citation needed]
- jashmatthews 9y agohttps://github.com/golang/go/issues/12061 https://github.com/golang/go/issues/12061 "Mark termination does not have to rescan stacks that haven’t executed since the last scan" With pre-emptive scheduling of OS threads, you potentially dirty a ton more stacks, and have to scan them all for pointers to heap memory. I'm not sure how VMs using lots of OS threads deal with this.
- coldtea 9y ago>So yes, you can. I didn't check how much memory it'd take, however, or attempt to measure overheads in any way, so I'm not saying there aren't potential issues with it. The "easily" part wasn't referring to feasibility, but to how effortless it is to do AND have performance and scalable code.