Permalink
Browse files

Don't use multi-threads to create redis connection

Change-Id: Ic5e2616ab893ff5a6146d7dcd9d1333b66de32de
  • Loading branch information...
1 parent 00b1fd1 commit 80068b9a5c6bed2fec9191ebfbfe06cbedc54d74 Tang Rui committed Jan 6, 2013
Showing with 10 additions and 15 deletions.
  1. +10 −15 sinatra/app_sinatra_service_quota/main.rb
@@ -450,25 +450,20 @@
# max_clients of redis
post '/service/redis/clients/:clients' do
e1 = nil
- threads = []
- Thread.abort_on_exception = true
+ redis_clients = []
clients_number = 0
- params[:clients].to_i.times do
- sleep 0.01
- threads << Thread.new do
- begin
- client = load_redis
- client.set('abc', 'test')
- sleep 10
- clients_number += 1
- rescue => e
- if e != nil && e != ""
- e1 = e
- end
+ params[:clients].to_i.times { redis_clients << load_redis }
+ redis_clients.each do |client|
+ begin
+ client.set('abc', 'test')
+ clients_number += 1
+ rescue => e
+ if e != nil && e != ""
+ e1 = e
+ break
end
end
end
- threads.each { |t| t.join }
if e1
"#{clients_number}-#{e1}"
else

0 comments on commit 80068b9

Please sign in to comment.