{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"open","user":{"avatar_url":"https://secure.gravatar.com/avatar/7379345fed54f2447537068ed1c2e440?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"7379345fed54f2447537068ed1c2e440","url":"https://api.github.com/users/antirez","login":"antirez","id":65632},"milestone":null,"updated_at":"2011-10-27T19:30:51Z","labels":[],"assignee":null,"comments":7,"closed_at":null,"url":"https://api.github.com/repos/ezmobius/redis-rb/issues/153","body":"Hello,\r\n\r\nI'm writing a Sinatra/Redis application, and so far I used something like that to create my Redis object:\r\n\r\n    before do\r\n        $r = Redis.new(:host => RedisHost, :port => RedisPort) if !$r\r\n    end\r\n\r\nSo basically all the web server threads are sharing the same Redis connection. Once the number of parallel clients using the web application grows the locking needed in redis-rb makes this approach not super efficient, so I wanted to switch to a connection pool.\r\n\r\nThe pool was designed in order to use only a single connection for a whole request, and is as simple as this:\r\n\r\n```\r\nRedisPoolSize = 10\r\ndef setup_redis_connection\r\n    $rpool = Array.new(RedisPoolSize) if !$rpool\r\n    i = rand(RedisPoolSize)\r\n    $rpool[i] = Redis.new(:host => RedisHost, :port => RedisPort) if !$rpool[i]\r\n    $r = $rpool[i]\r\nend\r\n\r\nbefore do\r\n    setup_redis_connection\r\nend\r\n```\r\n\r\nThis way I hoped to reduce the contention between different web server threads.\r\nHowever this does not work, hanging the application.\r\n\r\nFrom a first glance to the source code it seems like there is a deadlock, and this deadlock may be caused by redis-rb using a single lock for all the instances, but I'm not sure about this since I don't full understand the file monitor.rb for lack of familiarity with Ruby threading.\r\n\r\nThank you in advance for any help on this issue.\r\n\r\nSalvatore","html_url":"https://github.com/ezmobius/redis-rb/issues/153","title":"connections pool and synchronize","number":153,"id":1925919,"created_at":"2011-10-17T07:48:23Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/7379345fed54f2447537068ed1c2e440?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"7379345fed54f2447537068ed1c2e440","url":"https://api.github.com/users/antirez","login":"antirez","id":65632},"updated_at":"2011-10-27T19:30:51Z","url":"https://api.github.com/repos/ezmobius/redis-rb/issues/comments/2548183","body":"On Thu, Oct 27, 2011 at 9:24 PM, Pieter Noordhuis\n<reply@reply.github.com>\nwrote:\n> I can't reproduce the issue, using the exact same Ruby version and exact same set of gems. I run ab from a Ubuntu VM, with varying concurrency, and varying number of requests, but the app never hangs.\n\nHi Pieter! Will try to write a short program doing exactly what my\nreal program (lamernews) is doing to see if I can reproduce it easily.\n\nBtw the way I obtained the problem in the first instance is just\nsubstituting the current lamernews connection handling with the one\nproposed in this bug report.\n\nThanks for looking into it.\n\nSalvatore\n\n>\n> --\n> Reply to this email directly or view it on GitHub:\n> https://github.com/ezmobius/redis-rb/issues/153#issuecomment-2548117\n>\n\n\n\n-- \nSalvatore 'antirez' Sanfilippo\nopen source developer - VMware\n\nhttp://invece.org\n\"We are what we repeatedly do. Excellence, therefore, is not an act,\nbut a habit.\" -- Aristotele","id":2548183,"created_at":"2011-10-27T19:30:51Z"}}