Permalink
Browse files

testy

  • Loading branch information...
1 parent 176f7a0 commit 50e687720fbe9cc29fe936a3504ae6a0fa63924f Roman Kamyk committed Sep 3, 2011
Showing with 28 additions and 16 deletions.
  1. +9 −8 twitter/app/actions/HomeTimeline.rb
  2. +7 −1 twitter/app/actions/UserTimeline.rb
  3. +12 −7 twitter/app/model.rb
@@ -7,15 +7,16 @@ def start
DB.new.home_timeline(params[:screen_name]) do |tweets|
if tweets.nil?
render "Czego?\n"
- return finish
+ finish
+ else
+ render '['
+ result = tweets.map do |row|
+ %{{"created_at":"#{row['created_at']}","text":"#{row['text']}","id":#{row['id']},"user":{"id":#{row['user_id']},"name":"#{row['name']}","screen_name":"#{row['screen_name']}"}}}
+ end.join(",\n")
+ render result
+ render ']'
+ finish
end
- render '['
- result = tweets.map do |row|
- %{{"created_at":"#{row['created_at']}","text":"#{row['text']}","id":#{row['id']},"user":{"id":#{row['user_id']},"name":"#{row['name']}","screen_name":"#{row['screen_name']}"}}}
- end.join(",\n")
- render result
- render ']'
- finish
end
end
end
@@ -9,7 +9,13 @@ def start
pool.release(fiber)
else
#puts "Query on #{fiber.inspect}"
- db.aquery("SELECT * FROM statuses WHERE user_id = #{id}").callback do |r|
+ q = db.aquery("SELECT * FROM statuses WHERE user_id = #{id}")
+ q.errback do |r|
+ puts "Error123: #{r}"
+ finish
+ pool.release(fiber)
+ end
+ q.callback do |r|
render '['
result = r.map do |row|
%{{"created_at":"#{row['created_at']}","text":"#{row['text']}","id":#{row['id']}}}
View
@@ -84,9 +84,11 @@ def method_missing(method, *args, &blk)
class DB
SHARD_COUNT = 4
- MAX_CONN = 150
+ MAX_CONN = 8
DBCONN = {:host => "10.1.1.10", :username => "devcamp", :password => "devcamp"}
+ #DBCONN = {:host => "localhost", :username => "root"}
@@db = Twit::ConnectionPool.new(size: MAX_CONN/SHARD_COUNT) do
+ puts "PULA"
(1..SHARD_COUNT).map do |i|
Mysql2::EM::Client.new(DBCONN.merge(:database => "twitter#{i}"))
end
@@ -96,9 +98,13 @@ def db_for_user(name)
counter = SHARD_COUNT
ret = []
@@db.execute(true) do |acquired, fiber|
- #puts "me acquired"
acquired.each do |db|
- db.aquery("SELECT id FROM users WHERE screen_name = '#{name}'").callback do |r|
+ q = db.aquery("SELECT id FROM users WHERE screen_name = '#{name}'")
+ q.errback do |r|
+ puts "User get error: #{r}"
+ counter -= 1
+ end
+ q.callback do |r|
counter -= 1
if r.size > 0
r.each do |userRow|
@@ -119,8 +125,8 @@ def home_timeline(name, &blk)
if db.nil?
yield nil
else
- #puts user_id
- query_all("SELECT s.id, s.text, s.created_at, u.id AS user_id, u.name, u.screen_name FROM statuses s, followers f, users u WHERE u.id = s.user_id AND s.user_id = f.user_id AND f.follower_id = #{user_id}", &blk)
+ #query_all("SELECT s.id, s.text, s.created_at, u.id AS user_id, u.name, u.screen_name FROM statuses s, followers f, users u WHERE u.id = s.user_id AND s.user_id = f.user_id AND f.follower_id = #{user_id}", &blk)
+ yield nil
end
end
end
@@ -129,7 +135,7 @@ def query_all(query)
counter = SHARD_COUNT
result = []
@@db.execute(true) do |acquired, fiber|
- puts "Acquired pool"
+ #puts "Acquired pool"
check_finish = Proc.new do
#puts "Checking #{counter}"
counter -= 1
@@ -139,7 +145,6 @@ def query_all(query)
yield result
end
end
- p acquired.size
acquired.each do |db|
#puts "Querying: #{db.inspect}"
begin

0 comments on commit 50e6877

Please sign in to comment.