Array as a queue

22 views
Skip to first unread message

Funny Falcon

unread,
Jun 24, 2012, 8:34:10 AM6/24/12
to theco...@googlegroups.com
I've add patch (I tend to call it Fix) to ruby which makes Array to be perfectly usable as a queue.
It's in `ary-queue/ruby_1_9_3` branch of tcs ruby.

Motivation: https://gist.github.com/2052650

Testing after before and after patch applied: https://gist.github.com/2981959

Pull request to ruby-trunk https://github.com/ruby/ruby/pull/133
Issue https://bugs.ruby-lang.org/issues/6638

With regards,
Sokolov Yura aka funny-falcon

Jon

unread,
Jun 27, 2012, 3:34:12 PM6/27/12
to theco...@googlegroups.com
> I've add patch (I tend to call it Fix) to ruby which makes Array to be
> perfectly usable as a queue.
> It's in `ary-queue/ruby_1_9_3` branch of tcs ruby.
>
> Motivation: https://gist.github.com/2052650
>
> Testing after before and after patch applied:
> https://gist.github.com/2981959
>
> Pull request to ruby-trunk https://github.com/ruby/ruby/pull/133
> Issue https://bugs.ruby-lang.org/issues/6638

Looks cool. What real-world scenarios have you found this to be most helpful?

While I'm mostly invisible for the next ~4-5 weeks as I complete back-to-back biz trips, I'm inclined to (shortly) push out a maintenance tcs release with this included.

I've only had time to skim your other emails on ruby-core and ruby-talk, but do you think the `ary-queue/ruby_1_9_3` branch is solid enough to include in a new tcs 1.9.3 release? Any testing done on Win7 32bit or 64bit? Any microbenchmark (simulating a real-world scenario) we should use for a-b perf comparisons?

Jon

---
Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
http://thecodeshop.github.com | http://jonforums.github.com/
twitter: @jonforums

Funny Falcon

unread,
Jun 28, 2012, 2:16:06 AM6/28/12
to theco...@googlegroups.com
Real-world scenario: EventMachine uses Array as queue for EM.next_tick and EM::Queue, and when number of simultaneous requests goes over 200,
EventMachine becomes to be slower simply because of non-linear Array behavior in such pattern. With number of connections over 1000 the performance
loss could be over 20-30% simply cause of this issue.

(note that EM 0.12.0 used technique with flipping arrays to avoid this issue, but 1.0.0.beta uses #push/#shift on the same array)

Same issue were counted with usage of ::Queue : http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/391324  - it simply become to throttle at some
point cause it also uses Array as a storage. With this patch, ::Queue performance remains stable all over the time.

Excuse me for not doing testing other than on Ubuntu 12.04 64bit (I have no other machine at the moment). `make check` seem to run smoothly on this platform,
and I see no crossplatform reasons for them to fail on others.

Benchmark script mentioned as motivation https://gist.github.com/2052650#file_ary_as_queue.rb could be used as microbenchmark.
I suppose that with count parameter as 2 it perfectly simulates typical queue loads in EventMachine (and I think, in ::Queue usage also).

среда, 27 июня 2012 г., 23:34:12 UTC+4 пользователь Jon написал:

Funny Falcon

unread,
Jun 28, 2012, 2:25:56 AM6/28/12
to theco...@googlegroups.com
Excuse me, I meant these script as microbenchmark https://gist.github.com/2981959#file_ary_as_queue.rb
Reply all
Reply to author
Forward
0 new messages