Re: [sunshowers] Connection counter example
- Eric Wong
- 2009-12-29 @ 19:52
Makoto Inoue <firstname.lastname@example.org> wrote:
> Hi, Eric.
> I am currently trying to work out a way to display a number of
> connections to the sunshowers server. Here is my code(just added
> connection variable in your sample.)
> Then I did the following test and got very weired result.
> 1. Opening 10 new pages 1 by 1. = It's mostly incrementing, but
> sometimes starts from random number.
> 2. Closing 10 already opened pages 1 by 1. = Work as expected.
> Decrementing the number one by one.
> 3. Keep refreshing same page 10 times. = Connection never increment more than 2.
> Do you know which of the following causing the problem?
> A: my code is wrong
> B: bug on sunshowers or rainbows.
> C: Some limitation on ThreadPool concurrency model (I set
> worker_processes to 2 and worker_connection to 10) for this kind of
> My guess is the combination of A & C:
> Maybe the "connection" variable is not shared among different
> worker_process (and I should not use local variable for data storage
> for concurrent access)?
Local variables are exactly that, local to the block/scope/process.
Processes do not share any written memory by default (and it's
not easy to share writable memory in Ruby).
> Can I avoid this problem if I choose different concurrency model(such
> as Revactor or FiberPool)?
No, you can avoid this if you use only one worker process. Keep in mind
that you can only use a single CPU in most cases because of the global
VM lock in Ruby 1.9.
> If the above does not work, I guess I can work around by
> setting/getting value from memcache or redis?
That's probably the most scalable solution if you need multiple worker
processes (or even multiple machines).
Side note: I noticed EAGAIN was still getting logged in your gists,
I'll fix Rainbows! for that :)