droonga-client 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/droonga-request CHANGED
@@ -56,7 +56,7 @@ end
56
56
  available_protocols = [:droonga, :http]
57
57
  parser.on("--protocol=PROTOCOL", available_protocols,
58
58
  "Protocol to be used to communicate with Droonga system.",
59
- "[#{available_protocols.join('|')}",
59
+ "[#{available_protocols.join('|')}]",
60
60
  "(#{options[:protocol]})") do |protocol|
61
61
  options[:protocol] = protocol
62
62
  end
@@ -102,21 +102,28 @@ client = Droonga::Client.new(options)
102
102
  json_parser = Yajl::Parser.new
103
103
  json_parser.on_parse_complete = lambda do |request_message|
104
104
  if options[:report_request]
105
- print("Request: ")
105
+ message = "Request: "
106
106
  begin
107
- puts(JSON.pretty_generate(request_message))
107
+ message << JSON.pretty_generate(request_message)
108
108
  rescue
109
- p(request_message)
109
+ message << request_message.inspect
110
110
  end
111
+ message << "\n"
112
+ print(message)
111
113
  end
112
114
  start = Time.now
113
115
  request = client.request(request_message) do |response|
114
- puts("Elapsed time: #{Time.now - start}") if options[:report_elapsed_time]
116
+ message = ""
117
+ if options[:report_elapsed_time]
118
+ message << "Elapsed time: #{Time.now - start}\n"
119
+ end
115
120
  begin
116
- puts(JSON.pretty_generate(response))
121
+ message << JSON.pretty_generate(response)
117
122
  rescue
118
- p(response)
123
+ message << response.inspect
119
124
  end
125
+ message << "\n"
126
+ print(message)
120
127
  break if options[:exit_on_response]
121
128
  end
122
129
  request.wait
data/bin/droonga-send ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2014 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "ostruct"
19
+ require "optparse"
20
+ require "yajl"
21
+ require "json"
22
+
23
+ require "droonga/client"
24
+
25
+ options = OpenStruct.new
26
+ options.report_request = false
27
+ options.report_throughput = false
28
+
29
+ servers = []
30
+ default_server = "droonga:localhost:24224/droonga"
31
+ messages_per_second = Droonga::Client::RateLimiter::NO_LIMIT
32
+
33
+ def parse_server(server)
34
+ connect_info, tag = server.split(/\//, 2)
35
+ protocol, host, port = connect_info.split(/:/, 3)
36
+ {
37
+ :host => host,
38
+ :port => Integer(port),
39
+ :protocol => protocol.to_sym,
40
+ }
41
+ end
42
+
43
+ class ThroughputReporter
44
+ def initialize
45
+ @start_time = Time.now
46
+ @measure_start_time = Time.now
47
+ @n_sent_messages = 0
48
+ @first_report = true
49
+ end
50
+
51
+ def on_message_sent
52
+ @n_sent_messages += 1
53
+ current_time = Time.now
54
+ measure_span_in_second = current_time - @measure_start_time
55
+ if measure_span_in_second > 1
56
+ messages_per_second = @n_sent_messages / measure_span_in_second
57
+ if @first_report
58
+ @first_report = false
59
+ else
60
+ move_to_previous_line
61
+ end
62
+ print("% 8.3f messages/second\n" % messages_per_second)
63
+ @n_sent_messages = 0
64
+ @measure_start_time = current_time
65
+ end
66
+ end
67
+
68
+ private
69
+ def move_to_previous_line
70
+ print("\e[1A\r")
71
+ end
72
+ end
73
+
74
+ parser = OptionParser.new
75
+ parser.banner += " REQUEST_JSON_FILE1 REQUEST_JSON_FILE2 ..."
76
+ parser.separator("")
77
+ parser.separator("Connection:")
78
+ parser.on("--server=PROTOCOL:HOST:PORT/TAG",
79
+ "Droonga server to be connected.",
80
+ "Use multiple servers to use round-robin requests.",
81
+ "Specify this option multiple times to use multiple servers.",
82
+ "(#{default_server})") do |server|
83
+ servers << server
84
+ end
85
+ parser.on("--messages-per-second=N", Integer,
86
+ "Apply rate limitation by N messages/second.",
87
+ "'#{Droonga::Client::RateLimiter::NO_LIMIT}' means no limit.",
88
+ "(#{messages_per_second})") do |n|
89
+ messages_per_second = n
90
+ end
91
+ parser.separator("")
92
+ parser.separator("Report:")
93
+ parser.on("--[no-]report-request",
94
+ "Reports request message.",
95
+ "(#{options.report_request})") do |report_request|
96
+ options.report_request = report_request
97
+ end
98
+ parser.on("--report-throughput",
99
+ "Reports throughput by messages per second.",
100
+ "(no)") do
101
+ options.report_throughput = true
102
+ end
103
+ request_json_files = parser.parse!(ARGV)
104
+
105
+ servers << default_server if servers.empty?
106
+ clients = servers.collect do |server|
107
+ client_options = parse_server(server)
108
+ client = Droonga::Client.new(client_options)
109
+ Droonga::Client::RateLimiter.new(client, messages_per_second)
110
+ end
111
+
112
+ if options.report_throughput
113
+ throughput_reporter = ThroughputReporter.new
114
+ end
115
+
116
+ client_index = 0
117
+ json_parser = Yajl::Parser.new
118
+ json_parser.on_parse_complete = lambda do |request_message|
119
+ if options.report_request
120
+ message = "Request: "
121
+ begin
122
+ message << JSON.pretty_generate(request_message)
123
+ rescue
124
+ message << request_message.inspect
125
+ end
126
+ message << "\n"
127
+ print(message)
128
+ end
129
+ client = clients[client_index]
130
+ client.send(request_message)
131
+ client_index = (client_index + 1) % clients.size
132
+ throughput_reporter.on_message_sent if throughput_reporter
133
+ end
134
+
135
+ if request_json_files.empty?
136
+ json_parser.parse($stdin)
137
+ else
138
+ request_json_files.each do |request_json_file|
139
+ File.open(request_json_file) do |input|
140
+ json_parser.parse(input)
141
+ end
142
+ end
143
+ end
data/doc/text/news.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # News
2
2
 
3
+ ## 0.1.5: 2014-03-29
4
+
5
+ ### Improvements
6
+
7
+ * droonga-request: Reported results correctly event if there were multiple threads.
8
+ * Added a new command `droonga-send` just for sending requests and ignoring responses.
9
+
3
10
  ## 0.1.4: 2014-02-28
4
11
 
5
12
  ### Improvements
@@ -26,14 +26,13 @@ module Droonga
26
26
  class Client
27
27
  module Connection
28
28
  class HTTP
29
- # The error class for invalid HTTP method case
30
29
  class InvalidHTTPMethodError < Error
31
30
  attr_reader :http_method
32
31
  attr_reader :request_message
33
32
  def initialize(http_method, request_message)
34
33
  @http_method = http_method
35
34
  @request_message = request_message
36
- super("Unsupport HTTP Method: <#{@http_method}>: " +
35
+ super("Invalid HTTP Method: <#{@http_method}>: " +
37
36
  "<#{@request_message.inspect}>")
38
37
  end
39
38
  end
@@ -0,0 +1,57 @@
1
+ # Copyright (C) 2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ module Droonga
17
+ class Client
18
+ class RateLimiter
19
+ NO_LIMIT = -1
20
+
21
+ def initialize(client, messages_per_second)
22
+ @client = client
23
+ @messages_per_second = messages_per_second
24
+ @diff_in_seconds_per_message = 1.0 / @messages_per_second
25
+ end
26
+
27
+ def send(*args, &block)
28
+ limit do
29
+ @client.send(*args, &block)
30
+ end
31
+ end
32
+
33
+ def method_missing(name, *args, &block)
34
+ if @client.respond_to?(name)
35
+ @client.__send__(name, *args, &block)
36
+ else
37
+ super
38
+ end
39
+ end
40
+
41
+ private
42
+ def limit
43
+ return yield if @messages_per_second == NO_LIMIT
44
+
45
+ @previous_time ||= Time.now
46
+ diff_in_seconds = Time.now - @previous_time
47
+ sleep_time = @diff_in_seconds_per_message - diff_in_seconds
48
+ if sleep_time > 0
49
+ sleep(sleep_time)
50
+ end
51
+ @previous_time = Time.now
52
+
53
+ yield
54
+ end
55
+ end
56
+ end
57
+ end
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Droonga
19
19
  class Client
20
- VERSION = "0.1.4"
20
+ VERSION = "0.1.5"
21
21
  end
22
22
  end
@@ -18,7 +18,8 @@
18
18
  require "droonga/client/version"
19
19
  require "droonga/client/error"
20
20
  require "droonga/client/connection/http"
21
- require "droonga/client/connection/droonga_protocol"
21
+ require "droonga/client/connection/droonga-protocol"
22
+ require "droonga/client/rate-limiter"
22
23
 
23
24
  module Droonga
24
25
  class Client
@@ -43,8 +44,6 @@ module Droonga
43
44
  end
44
45
  end
45
46
 
46
- attr_reader :connection
47
-
48
47
  # Creates a new Droonga Engine client.
49
48
  #
50
49
  # @param options [Hash] Options to connect Droonga Engine.
metadata CHANGED
@@ -1,118 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droonga-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Droonga Project
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
12
+ date: 2014-03-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: msgpack
15
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &76032510 !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
24
+ version_requirements: *76032510
27
25
  - !ruby/object:Gem::Dependency
28
26
  name: fluent-logger
29
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &76032280 !ruby/object:Gem::Requirement
28
+ none: false
30
29
  requirements:
31
- - - '>='
30
+ - - ! '>='
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
35
+ version_requirements: *76032280
41
36
  - !ruby/object:Gem::Dependency
42
37
  name: rack
43
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &76032070 !ruby/object:Gem::Requirement
39
+ none: false
44
40
  requirements:
45
- - - '>='
41
+ - - ! '>='
46
42
  - !ruby/object:Gem::Version
47
43
  version: '0'
48
44
  type: :runtime
49
45
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
46
+ version_requirements: *76032070
55
47
  - !ruby/object:Gem::Dependency
56
48
  name: yajl-ruby
57
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &76031860 !ruby/object:Gem::Requirement
50
+ none: false
58
51
  requirements:
59
- - - '>='
52
+ - - ! '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  type: :runtime
63
56
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
57
+ version_requirements: *76031860
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: bundler
71
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &76031610 !ruby/object:Gem::Requirement
61
+ none: false
72
62
  requirements:
73
63
  - - ~>
74
64
  - !ruby/object:Gem::Version
75
65
  version: '1.3'
76
66
  type: :development
77
67
  prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: '1.3'
68
+ version_requirements: *76031610
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rake
85
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &76031400 !ruby/object:Gem::Requirement
72
+ none: false
86
73
  requirements:
87
- - - '>='
74
+ - - ! '>='
88
75
  - !ruby/object:Gem::Version
89
76
  version: '0'
90
77
  type: :development
91
78
  prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
79
+ version_requirements: *76031400
97
80
  - !ruby/object:Gem::Dependency
98
81
  name: packnga
99
- requirement: !ruby/object:Gem::Requirement
82
+ requirement: &76031170 !ruby/object:Gem::Requirement
83
+ none: false
100
84
  requirements:
101
- - - '>='
85
+ - - ! '>='
102
86
  - !ruby/object:Gem::Version
103
87
  version: '0'
104
88
  type: :development
105
89
  prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
90
+ version_requirements: *76031170
111
91
  description: Droonga client for Ruby
112
92
  email:
113
93
  - droonga@groonga.org
114
94
  executables:
115
95
  - droonga-request
96
+ - droonga-send
116
97
  extensions: []
117
98
  extra_rdoc_files: []
118
99
  files:
@@ -123,37 +104,40 @@ files:
123
104
  - README.md
124
105
  - Rakefile
125
106
  - bin/droonga-request
107
+ - bin/droonga-send
126
108
  - doc/text/news.md
127
109
  - droonga-client.gemspec
128
110
  - lib/droonga/client.rb
129
- - lib/droonga/client/connection/droonga_protocol.rb
111
+ - lib/droonga/client/connection/droonga-protocol.rb
130
112
  - lib/droonga/client/connection/error.rb
131
113
  - lib/droonga/client/connection/http.rb
132
114
  - lib/droonga/client/error.rb
115
+ - lib/droonga/client/rate-limiter.rb
133
116
  - lib/droonga/client/version.rb
134
117
  homepage: https://github.com/droonga/droonga-client-ruby
135
118
  licenses:
136
119
  - LGPL-2.1
137
- metadata: {}
138
120
  post_install_message:
139
121
  rdoc_options: []
140
122
  require_paths:
141
123
  - lib
142
124
  required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
143
126
  requirements:
144
- - - '>='
127
+ - - ! '>='
145
128
  - !ruby/object:Gem::Version
146
129
  version: 1.9.3
147
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
148
132
  requirements:
149
- - - '>='
133
+ - - ! '>='
150
134
  - !ruby/object:Gem::Version
151
135
  version: '0'
152
136
  requirements: []
153
137
  rubyforge_project:
154
- rubygems_version: 2.0.14
138
+ rubygems_version: 1.8.11
155
139
  signing_key:
156
- specification_version: 4
140
+ specification_version: 3
157
141
  summary: Droonga client for Ruby
158
142
  test_files: []
159
143
  has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 675e62f644e94a104c8a0dd03af1b9f709e4630f
4
- data.tar.gz: 321c2a3767f06127ea58cf8d678b192fbe174137
5
- SHA512:
6
- metadata.gz: 7f8662c7e20b9499e1b1d8dedd986bdaffeced96c8b22b285b799926de08d562b8196456b20e3efd33f6cf8c4323736a4e82f1e9778f5281e0f2195b87e26e2b
7
- data.tar.gz: 0485dce6429eb9c6c5da1684b0ef1ce56d3e71174c451fa9c13d5e026f18dc975cbc07f8d399589bd3cf54841591937b90264c09977f86013ef0258416e0e459