Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

seemingly correct line protocol parser

  • Loading branch information...
commit 903dd7651af8c432a281f40605b5f5eb8acfe6c4 1 parent 32f5b53
Nick Kallen authored
View
22 log/joke_server.rb.log
@@ -1230,3 +1230,25 @@
2009-04-16T17:28:24-07:00 13412-1239928103-4847 0.165890 0.000100 0.000100
2009-04-16T17:28:24-07:00 13413-1239928104-9537 0.701739 0.000100 0.000100
2009-04-16T17:28:25-07:00 13414-1239928104-5926 0.701963 0.000100 0.000100
+2009-04-16T17:40:16-07:00 13409-1239928816-3051 0.441173 0.000100 0.000100
+2009-04-16T17:40:19-07:00 13410-1239928818-5317 0.863798 0.000100 0.000100
+2009-04-16T17:40:22-07:00 13411-1239928822-6337 0.629695 0.000100 0.000100
+2009-04-16T17:40:23-07:00 13412-1239928822-6891 0.963588 0.000100 0.000100
+2009-04-16T17:40:23-07:00 13413-1239928823-6380 0.122551 0.000100 0.010000
+2009-04-16T17:50:05-07:00 13409-1239929405-2459 0.213181 0.000100 0.000100
+2009-04-16T17:50:06-07:00 13410-1239929406-7473 0.386062 0.000100 0.000100
+2009-04-16T17:50:07-07:00 13411-1239929406-9724 0.867151 0.000100 0.000100
+2009-04-16T17:50:07-07:00 13412-1239929407-2604 0.035577 0.000100 0.000100
+2009-04-16T17:50:08-07:00 13413-1239929407-8729 0.990558 0.000100 0.000100
+2009-04-16T17:50:09-07:00 13414-1239929408-1207 0.822471 0.000100 0.000100
+2009-04-16T17:50:10-07:00 13415-1239929409-8578 0.468514 0.000100 0.000100
+2009-04-16T17:50:10-07:00 13416-1239929410-2728 0.229222 0.000100 0.000100
+2009-04-16T17:50:11-07:00 13417-1239929410-5984 0.643820 0.000100 0.000100
+2009-04-16T17:50:11-07:00 13418-1239929411-5297 0.548832 0.000100 0.000100
+2009-04-16T17:50:11-07:00 13409-1239929411-9125 0.025767 0.000100 0.010000
+2009-04-16T17:50:12-07:00 13410-1239929411-3115 0.825727 0.000100 0.000100
+2009-04-16T17:50:12-07:00 13411-1239929412-4438 0.387799 0.000100 0.000100
+2009-04-16T17:50:13-07:00 13412-1239929412-330 0.317319 0.000100 0.000100
+2009-04-16T17:50:13-07:00 13413-1239929413-1250 0.326542 0.000100 0.000100
+2009-04-16T17:50:14-07:00 13414-1239929413-5220 0.993371 0.000100 0.000100
+2009-04-16T17:50:14-07:00 13415-1239929414-4252 0.178418 0.000100 0.000100
View
29 log/proxy.rb.log
@@ -1194,3 +1194,32 @@
2009-04-16T17:28:24-07:00 13551-1239928103-8019 0.166559 0.000100 0.000100
2009-04-16T17:28:24-07:00 13551-1239928104-6146 0.702492 0.000100 0.000100
2009-04-16T17:28:25-07:00 13551-1239928104-1436 0.702699 0.000100 0.000100
+# Fields: job_user job_sys job_real
+# Fields: job_user job_sys job_real
+# Fields: job_user job_sys job_real
+# Fields: job_user job_sys job_real
+# Fields: job_user job_sys job_real
+# Fields: job_user job_sys job_real
+2009-04-16T17:40:16-07:00 13681-1239928816-3343 0.442761 0.000100 0.000100
+2009-04-16T17:40:19-07:00 13681-1239928818-3802 0.864440 0.000100 0.000100
+2009-04-16T17:40:22-07:00 13681-1239928822-1302 0.630345 0.000100 0.000100
+2009-04-16T17:40:23-07:00 13681-1239928822-1497 0.964366 0.000100 0.000100
+2009-04-16T17:40:23-07:00 13681-1239928823-5016 0.123250 0.000100 0.000100
+# Fields: job_user job_sys job_real
+2009-04-16T17:50:05-07:00 13700-1239929405-8214 0.214934 0.000100 0.000100
+2009-04-16T17:50:06-07:00 13700-1239929406-3731 0.386758 0.000100 0.000100
+2009-04-16T17:50:07-07:00 13700-1239929406-6075 0.867830 0.000100 0.000100
+2009-04-16T17:50:07-07:00 13700-1239929407-5697 0.036265 0.000100 0.000100
+2009-04-16T17:50:08-07:00 13700-1239929407-9737 0.991322 0.000100 0.000100
+2009-04-16T17:50:09-07:00 13700-1239929408-7796 0.823158 0.000100 0.000100
+2009-04-16T17:50:10-07:00 13700-1239929409-4588 0.469160 0.000100 0.000100
+2009-04-16T17:50:10-07:00 13700-1239929410-749 0.229894 0.000100 0.000100
+2009-04-16T17:50:11-07:00 13700-1239929410-3634 0.644488 0.000100 0.000100
+2009-04-16T17:50:11-07:00 13700-1239929411-6814 0.549533 0.000100 0.000100
+2009-04-16T17:50:11-07:00 13700-1239929411-7259 0.026458 0.000100 0.000100
+2009-04-16T17:50:12-07:00 13700-1239929411-1270 0.826452 0.000100 0.000100
+2009-04-16T17:50:12-07:00 13700-1239929412-9459 0.388378 0.000100 0.000100
+2009-04-16T17:50:13-07:00 13700-1239929412-7727 0.317941 0.000100 0.000100
+2009-04-16T17:50:13-07:00 13700-1239929413-9138 0.327251 0.000100 0.000100
+2009-04-16T17:50:14-07:00 13700-1239929413-9108 0.994035 0.000100 0.010000
+2009-04-16T17:50:14-07:00 13700-1239929414-7896 0.179096 0.000100 0.000100
View
7 proxy.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
['rubygems', 'activesupport', 'eventmachine', 'socket', 'optparse', 'statosaurus'].each { |dependency| require dependency }
-['proxy/server', 'proxy/balancers/first', 'proxy/balancers/random', 'proxy/balancers/round_robin', 'proxy/balancers/least_connections'].each { |dependency| require dependency }
+['util/line_protocol', 'proxy/server', 'proxy/balancers/first', 'proxy/balancers/random', 'proxy/balancers/round_robin', 'proxy/balancers/least_connections'].each { |dependency| require dependency }
begin
$options = {
@@ -23,15 +23,16 @@
end
module ProxyServer
+ include LineProtocol
include EventMachine::Deferrable
- def receive_data(data)
+ def call(data)
proxy = self
EventMachine.spawn do
p "spawning"
$stats.transaction do # TODO propagate txnid to server.
$stats.measure('job') do
- proxy.send_data(ProxyServer.forward(data))
+ proxy.send_data(ProxyServer.forward(data + "\n"))
end
end
end.run
View
15 util/line_protocol.rb
@@ -0,0 +1,15 @@
+['rubygems', 'eventmachine'].each { |dependency| require dependency }
+
+module LineProtocol
+ def receive_data(data)
+ @data ||= ""
+ if first_newline = data.index("\n")
+ call(@data + data[0..first_newline])
+ @data = ""
+ data_after_first_newline = data[(first_newline+1)..-1]
+ if data_after_first_newline
+ receive_data(data_after_first_newline)
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.