tag:blogger.com,1999:blog-15616477.post6455334409832016838..comments2023-10-22T11:49:21.348+03:00Comments on oldmoe: Ruby Fibers Vs Ruby Threadsoldmoehttp://www.blogger.com/profile/14341721253106429644noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-15616477.post-77692123113833773632010-01-02T17:54:59.111+02:002010-01-02T17:54:59.111+02:00hi oldmoe,
its quite like kilim written for java,...hi oldmoe,<br /><br />its quite like kilim written for java, actor based model of scala. If i got it right at the very first instance.<br /><br />Or the advanced stage of neverblock would be the above two. <br /><br />I think neverblock has been released now, or not? If not yet, would like to collaborate. <br /><br />Reach me at : abhishek.manocha@gmail.comchachahttps://www.blogger.com/profile/14428977734984912486noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-29429625942837798422008-09-23T20:34:00.000+02:002008-09-23T20:34:00.000+02:00Fiber is basically a thread, but it doesn't switch...Fiber is basically a thread, but it doesn't switch execution with other fibers--you have to manually control when it passes control back to the "parent" fiber.<BR/>see http://www.infoq.com/news/2007/08/ruby-1-9-fibersRoger Packhttps://www.blogger.com/profile/01578246846716577925noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-22417681186244159652008-09-23T19:33:00.000+02:002008-09-23T19:33:00.000+02:00hi folks,what exactly is the technical difference ...hi folks,<BR/><BR/>what exactly is the technical difference between a thread and a fiber. <BR/><BR/>I thought that threads are a piece of code, with a shared address space. I can create threads at user level or at OS level such as pthreads?<BR/><BR/>SanaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-15616477.post-3859235831337204442008-08-23T23:25:00.000+03:002008-08-23T23:25:00.000+03:00I am worried that having multiple threads will onl...I am worried that having multiple threads will only give me very little benefits with the GIL in action. I wont be able to use more than one processor anyway. That is why I am more inclined towards a worker process model. I am wondering if I could use sysv-ipc for communication, the idea is a master process with an eventloop and a group of workers each with its eventloop. <BR/>Communicating via pipes/sharedmemory/files depending on request/response size.<BR/><BR/>I still didn't write a line of code, only testing Francis' http server for EM (which is so so fast) would like to use it as a basis for the master process which should be the only process that listens on a socket.<BR/><BR/>Would love if you help out in any way. I would love to help with your generational GC myself. If only with testing.oldmoehttps://www.blogger.com/profile/14341721253106429644noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-18038703895921450322008-08-23T20:26:00.000+03:002008-08-23T20:26:00.000+03:00Yeah single threaded is probably fastest [my thoug...Yeah single threaded is probably fastest [my thought once had been to wonder if it were possible to rip out the thread handling stuff from core and run all async and disallow thread creation].<BR/>That being said, however, the one reason why it would make sense to have 'a few' worker threads is, as you mentioned once, if one thread does something that is computationally intensive it would stop all other outstanding requests, so...it may end up being useful. I haven't studied in depth the effect of having a 'few' threads [I know that having a lot of them is definitely bad, and that having one is best, but I'm unsure of the cost of a few. In my own tests it doesn't seem to hurt all that much, but I haven't researched it all that well.]<BR/>Good luck.<BR/>Let me know how or if I can help.<BR/>-=RAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-15616477.post-50212628629664263182008-08-21T18:09:00.000+03:002008-08-21T18:09:00.000+03:00I think having more than one thread in the system ...I think having more than one thread in the system will have a sizable overhead, it will kick start the thread scheduler which would not be needed at all otherwiseoldmoehttps://www.blogger.com/profile/14341721253106429644noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-725683586307097792008-08-20T19:33:00.000+03:002008-08-20T19:33:00.000+03:00You can see that threads [even if sleeping] provid...You can see that threads [even if sleeping] provide a small slowdown on Ruby:<BR/><BR/>>> Benchmark.measure { 10000.times { Fiber.new {}}}<BR/>=> # Benchmark::Tms:0x125a48 @label="", @real=0.270713090896606, @cstime=0.0, @cutime=0.0, @stime=0.15, @utime=0.12, @total=0.27><BR/><BR/><BR/>single threaded, this line took 0.27<BR/><BR/>now add some 1000 threads [just for kicks] -- all sleeping<BR/><BR/>>> 1000.times { Thread.new { sleep }}<BR/>=> 1000<BR/>>> Benchmark.measure { 10000.times { Fiber.new {}}}<BR/>=> # Benchmark::Tms:0x10c4a8 @label="", @real=0.588271141052246, @cstime=0.0, @cutime=0.0, @stime=0.32, @utime=0.26, @total=0.58><BR/><BR/>0.58seconds.<BR/><BR/>So I think you're right that threads do add at least a small bit of baggage and overhead.<BR/><BR/>-=RRoger Packhttps://www.blogger.com/profile/01578246846716577925noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-43866744312813937532008-08-19T18:12:00.000+03:002008-08-19T18:12:00.000+03:00Nice one, I didn't turn off the GC for those tests...Nice one, I didn't turn off the GC for those tests, need to redo the test sometime soon.<BR/><BR/>I am not sure of the fibers + threads mix thing. I am rather thinking of a master eventloop with forked worker processes, still contemplating though, should be writing code once this neverblock thing is officialy released.oldmoehttps://www.blogger.com/profile/14341721253106429644noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-11054199654401663182008-08-19T09:24:00.000+03:002008-08-19T09:24:00.000+03:00Also note that since rails will 'become thread saf...Also note that since rails will 'become thread safe' I wonder if having a few threads thrown into the mix wouldn't help things somehow. [1] A mix of fibers + a few threads. Maybe the overhead won't be too intense.<BR/>Thanks.<BR/>-=R [Mormon] :)<BR/><BR/>[1] http://weblog.rubyonrails.org/2008/8/16/josh-peek-officially-joins-the-rails-coreRoger Packhttps://www.blogger.com/profile/01578246846716577925noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-59656738339768996302008-08-18T23:41:00.000+03:002008-08-18T23:41:00.000+03:00I assume you turned off the GC for these tests, th...I assume you turned off the GC for these tests, then?<BR/>Thanks!<BR/>-=RAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-15616477.post-10977650144040137552008-08-18T23:40:00.000+03:002008-08-18T23:40:00.000+03:00Thanks.Thanks.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15616477.post-54367377936272335432008-08-18T13:39:00.000+03:002008-08-18T13:39:00.000+03:00I have implemented a fiber pool, part of the soon ...I have implemented a fiber pool, part of the soon to be released neverblock library, check it out here:<BR/><BR/>http://github.com/oldmoe/neverblockoldmoehttps://www.blogger.com/profile/14341721253106429644noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-6820517169238404162008-08-18T09:32:00.000+03:002008-08-18T09:32:00.000+03:00As a note, it appears that running resume on a fib...As a note, it appears that running resume on a fiber is faster than creating a new one:<BR/><BR/>>> a = Fiber.new { loop { Fiber.yield }}<BR/>>> Benchmark.measure { 10000.times { a.resume}}<BR/>=> # Benchmark::Tms:0x0d7adc @label="", @real=0.109291076660156, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.05, @total=0.05><BR/>>> Benchmark.measure { 10000.times { b = Fiber.new {}}}<BR/>=> # Benchmark::Tms:0x121dbc @label="", @real=0.298281908035278, @cstime=0.0, @cutime=0.0, @stime=0.15, @utime=0.13, @total=0.28><BR/><BR/>So I almost wonder if one could actually reuse fibers [like a fiber pool] to save on speed.<BR/>GL.<BR/>-=RAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-15616477.post-67002583463263349912008-08-03T05:59:00.000+03:002008-08-03T05:59:00.000+03:00Fibers are not even preemptive. Inside a given thr...Fibers are not even preemptive. Inside a given thread, only one fiber can run at a time. Fibers need to yield to their caller to allow for other fibers to run.<BR/><BR/>Delegating the fibers to another thread might save you when the blocking code is Ruby scheduler aware. But most c extensions will block your the whole of your interpreter anyway (unless you do all your IO in a non blocking way)oldmoehttps://www.blogger.com/profile/14341721253106429644noreply@blogger.comtag:blogger.com,1999:blog-15616477.post-63818093489627454722008-08-03T03:27:00.000+03:002008-08-03T03:27:00.000+03:00Are fibers equivalent to ruby 1.8 green threads in...Are fibers equivalent to ruby 1.8 green threads in that they can only run on one processor and all fibers will stop processing if one of them does an IO blocking operation? It might be interesting to combine threads and fibers so you spawn a thread that then creates the fibers, stopping your main thread from ever becoming blocked.jemmywhttps://www.blogger.com/profile/05749427918648116813noreply@blogger.com