Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

seemingly correct line protocol parser

  • Loading branch information...
commit 903dd7651af8c432a281f40605b5f5eb8acfe6c4 1 parent 32f5b53
Nick Kallen authored
22 log/joke_server.rb.log
@@ -1230,3 +1230,25 @@
1230 1230 2009-04-16T17:28:24-07:00 13412-1239928103-4847 0.165890 0.000100 0.000100
1231 1231 2009-04-16T17:28:24-07:00 13413-1239928104-9537 0.701739 0.000100 0.000100
1232 1232 2009-04-16T17:28:25-07:00 13414-1239928104-5926 0.701963 0.000100 0.000100
  1233 +2009-04-16T17:40:16-07:00 13409-1239928816-3051 0.441173 0.000100 0.000100
  1234 +2009-04-16T17:40:19-07:00 13410-1239928818-5317 0.863798 0.000100 0.000100
  1235 +2009-04-16T17:40:22-07:00 13411-1239928822-6337 0.629695 0.000100 0.000100
  1236 +2009-04-16T17:40:23-07:00 13412-1239928822-6891 0.963588 0.000100 0.000100
  1237 +2009-04-16T17:40:23-07:00 13413-1239928823-6380 0.122551 0.000100 0.010000
  1238 +2009-04-16T17:50:05-07:00 13409-1239929405-2459 0.213181 0.000100 0.000100
  1239 +2009-04-16T17:50:06-07:00 13410-1239929406-7473 0.386062 0.000100 0.000100
  1240 +2009-04-16T17:50:07-07:00 13411-1239929406-9724 0.867151 0.000100 0.000100
  1241 +2009-04-16T17:50:07-07:00 13412-1239929407-2604 0.035577 0.000100 0.000100
  1242 +2009-04-16T17:50:08-07:00 13413-1239929407-8729 0.990558 0.000100 0.000100
  1243 +2009-04-16T17:50:09-07:00 13414-1239929408-1207 0.822471 0.000100 0.000100
  1244 +2009-04-16T17:50:10-07:00 13415-1239929409-8578 0.468514 0.000100 0.000100
  1245 +2009-04-16T17:50:10-07:00 13416-1239929410-2728 0.229222 0.000100 0.000100
  1246 +2009-04-16T17:50:11-07:00 13417-1239929410-5984 0.643820 0.000100 0.000100
  1247 +2009-04-16T17:50:11-07:00 13418-1239929411-5297 0.548832 0.000100 0.000100
  1248 +2009-04-16T17:50:11-07:00 13409-1239929411-9125 0.025767 0.000100 0.010000
  1249 +2009-04-16T17:50:12-07:00 13410-1239929411-3115 0.825727 0.000100 0.000100
  1250 +2009-04-16T17:50:12-07:00 13411-1239929412-4438 0.387799 0.000100 0.000100
  1251 +2009-04-16T17:50:13-07:00 13412-1239929412-330 0.317319 0.000100 0.000100
  1252 +2009-04-16T17:50:13-07:00 13413-1239929413-1250 0.326542 0.000100 0.000100
  1253 +2009-04-16T17:50:14-07:00 13414-1239929413-5220 0.993371 0.000100 0.000100
  1254 +2009-04-16T17:50:14-07:00 13415-1239929414-4252 0.178418 0.000100 0.000100
29 log/proxy.rb.log
@@ -1194,3 +1194,32 @@
1194 1194 2009-04-16T17:28:24-07:00 13551-1239928103-8019 0.166559 0.000100 0.000100
1195 1195 2009-04-16T17:28:24-07:00 13551-1239928104-6146 0.702492 0.000100 0.000100
1196 1196 2009-04-16T17:28:25-07:00 13551-1239928104-1436 0.702699 0.000100 0.000100
  1197 +# Fields: job_user job_sys job_real
  1198 +# Fields: job_user job_sys job_real
  1199 +# Fields: job_user job_sys job_real
  1200 +# Fields: job_user job_sys job_real
  1201 +# Fields: job_user job_sys job_real
  1202 +# Fields: job_user job_sys job_real
  1203 +2009-04-16T17:40:16-07:00 13681-1239928816-3343 0.442761 0.000100 0.000100
  1204 +2009-04-16T17:40:19-07:00 13681-1239928818-3802 0.864440 0.000100 0.000100
  1205 +2009-04-16T17:40:22-07:00 13681-1239928822-1302 0.630345 0.000100 0.000100
  1206 +2009-04-16T17:40:23-07:00 13681-1239928822-1497 0.964366 0.000100 0.000100
  1207 +2009-04-16T17:40:23-07:00 13681-1239928823-5016 0.123250 0.000100 0.000100
  1208 +# Fields: job_user job_sys job_real
  1209 +2009-04-16T17:50:05-07:00 13700-1239929405-8214 0.214934 0.000100 0.000100
  1210 +2009-04-16T17:50:06-07:00 13700-1239929406-3731 0.386758 0.000100 0.000100
  1211 +2009-04-16T17:50:07-07:00 13700-1239929406-6075 0.867830 0.000100 0.000100
  1212 +2009-04-16T17:50:07-07:00 13700-1239929407-5697 0.036265 0.000100 0.000100
  1213 +2009-04-16T17:50:08-07:00 13700-1239929407-9737 0.991322 0.000100 0.000100
  1214 +2009-04-16T17:50:09-07:00 13700-1239929408-7796 0.823158 0.000100 0.000100
  1215 +2009-04-16T17:50:10-07:00 13700-1239929409-4588 0.469160 0.000100 0.000100
  1216 +2009-04-16T17:50:10-07:00 13700-1239929410-749 0.229894 0.000100 0.000100
  1217 +2009-04-16T17:50:11-07:00 13700-1239929410-3634 0.644488 0.000100 0.000100
  1218 +2009-04-16T17:50:11-07:00 13700-1239929411-6814 0.549533 0.000100 0.000100
  1219 +2009-04-16T17:50:11-07:00 13700-1239929411-7259 0.026458 0.000100 0.000100
  1220 +2009-04-16T17:50:12-07:00 13700-1239929411-1270 0.826452 0.000100 0.000100
  1221 +2009-04-16T17:50:12-07:00 13700-1239929412-9459 0.388378 0.000100 0.000100
  1222 +2009-04-16T17:50:13-07:00 13700-1239929412-7727 0.317941 0.000100 0.000100
  1223 +2009-04-16T17:50:13-07:00 13700-1239929413-9138 0.327251 0.000100 0.000100
  1224 +2009-04-16T17:50:14-07:00 13700-1239929413-9108 0.994035 0.000100 0.010000
  1225 +2009-04-16T17:50:14-07:00 13700-1239929414-7896 0.179096 0.000100 0.000100
7 proxy.rb
... ... @@ -1,7 +1,7 @@
1 1 #!/usr/bin/env ruby
2 2
3 3 ['rubygems', 'activesupport', 'eventmachine', 'socket', 'optparse', 'statosaurus'].each { |dependency| require dependency }
4   -['proxy/server', 'proxy/balancers/first', 'proxy/balancers/random', 'proxy/balancers/round_robin', 'proxy/balancers/least_connections'].each { |dependency| require dependency }
  4 +['util/line_protocol', 'proxy/server', 'proxy/balancers/first', 'proxy/balancers/random', 'proxy/balancers/round_robin', 'proxy/balancers/least_connections'].each { |dependency| require dependency }
5 5
6 6 begin
7 7 $options = {
@@ -23,15 +23,16 @@
23 23 end
24 24
25 25 module ProxyServer
  26 + include LineProtocol
26 27 include EventMachine::Deferrable
27 28
28   - def receive_data(data)
  29 + def call(data)
29 30 proxy = self
30 31 EventMachine.spawn do
31 32 p "spawning"
32 33 $stats.transaction do # TODO propagate txnid to server.
33 34 $stats.measure('job') do
34   - proxy.send_data(ProxyServer.forward(data))
  35 + proxy.send_data(ProxyServer.forward(data + "\n"))
35 36 end
36 37 end
37 38 end.run
15 util/line_protocol.rb
... ... @@ -0,0 +1,15 @@
  1 +['rubygems', 'eventmachine'].each { |dependency| require dependency }
  2 +
  3 +module LineProtocol
  4 + def receive_data(data)
  5 + @data ||= ""
  6 + if first_newline = data.index("\n")
  7 + call(@data + data[0..first_newline])
  8 + @data = ""
  9 + data_after_first_newline = data[(first_newline+1)..-1]
  10 + if data_after_first_newline
  11 + receive_data(data_after_first_newline)
  12 + end
  13 + end
  14 + end
  15 +end

0 comments on commit 903dd76

Please sign in to comment.
Something went wrong with that request. Please try again.