upfluence-thrift 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +43 -0
- data/benchmark/Benchmark.thrift +24 -0
- data/benchmark/benchmark.rb +271 -0
- data/benchmark/client.rb +74 -0
- data/benchmark/gen-rb/benchmark_constants.rb +11 -0
- data/benchmark/gen-rb/benchmark_service.rb +80 -0
- data/benchmark/gen-rb/benchmark_types.rb +10 -0
- data/benchmark/server.rb +82 -0
- data/benchmark/thin_server.rb +44 -0
- data/ext/binary_protocol_accelerated.c +460 -0
- data/ext/binary_protocol_accelerated.h +20 -0
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +637 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +99 -0
- data/ext/extconf.rb +34 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +134 -0
- data/ext/memory_buffer.h +20 -0
- data/ext/protocol.c +0 -0
- data/ext/protocol.h +0 -0
- data/ext/strlcpy.c +41 -0
- data/ext/strlcpy.h +34 -0
- data/ext/struct.c +707 -0
- data/ext/struct.h +25 -0
- data/ext/thrift_native.c +201 -0
- data/lib/thrift.rb +68 -0
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/client.rb +71 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/exceptions.rb +87 -0
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +57 -0
- data/lib/thrift/protocol/base_protocol.rb +379 -0
- data/lib/thrift/protocol/binary_protocol.rb +237 -0
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
- data/lib/thrift/protocol/compact_protocol.rb +435 -0
- data/lib/thrift/protocol/json_protocol.rb +769 -0
- data/lib/thrift/protocol/multiplexed_protocol.rb +40 -0
- data/lib/thrift/protocol/protocol_decorator.rb +194 -0
- data/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/thrift/server/base_server.rb +31 -0
- data/lib/thrift/server/mongrel_http_server.rb +60 -0
- data/lib/thrift/server/nonblocking_server.rb +305 -0
- data/lib/thrift/server/rack_application.rb +61 -0
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thin_http_server.rb +51 -0
- data/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/thrift/struct.rb +237 -0
- data/lib/thrift/struct_union.rb +192 -0
- data/lib/thrift/thrift_native.rb +24 -0
- data/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/thrift/transport/base_transport.rb +109 -0
- data/lib/thrift/transport/buffered_transport.rb +114 -0
- data/lib/thrift/transport/framed_transport.rb +117 -0
- data/lib/thrift/transport/http_client_transport.rb +56 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +139 -0
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +101 -0
- data/lib/thrift/union.rb +179 -0
- data/spec/BaseService.thrift +27 -0
- data/spec/ExtendedService.thrift +25 -0
- data/spec/Referenced.thrift +44 -0
- data/spec/ThriftNamespacedSpec.thrift +53 -0
- data/spec/ThriftSpec.thrift +183 -0
- data/spec/base_protocol_spec.rb +217 -0
- data/spec/base_transport_spec.rb +350 -0
- data/spec/binary_protocol_accelerated_spec.rb +42 -0
- data/spec/binary_protocol_spec.rb +66 -0
- data/spec/binary_protocol_spec_shared.rb +455 -0
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +99 -0
- data/spec/compact_protocol_spec.rb +143 -0
- data/spec/exception_spec.rb +141 -0
- data/spec/flat_spec.rb +62 -0
- data/spec/gen-rb/base/base_service.rb +80 -0
- data/spec/gen-rb/base/base_service_constants.rb +11 -0
- data/spec/gen-rb/base/base_service_types.rb +26 -0
- data/spec/gen-rb/extended/extended_service.rb +78 -0
- data/spec/gen-rb/extended/extended_service_constants.rb +11 -0
- data/spec/gen-rb/extended/extended_service_types.rb +12 -0
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +272 -0
- data/spec/gen-rb/flat/referenced_constants.rb +11 -0
- data/spec/gen-rb/flat/referenced_types.rb +17 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +28 -0
- data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +272 -0
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +28 -0
- data/spec/gen-rb/nonblocking_service.rb +272 -0
- data/spec/gen-rb/other_namespace/referenced_constants.rb +11 -0
- data/spec/gen-rb/other_namespace/referenced_types.rb +17 -0
- data/spec/gen-rb/thrift_spec_constants.rb +11 -0
- data/spec/gen-rb/thrift_spec_types.rb +538 -0
- data/spec/http_client_spec.rb +120 -0
- data/spec/json_protocol_spec.rb +513 -0
- data/spec/namespaced_spec.rb +67 -0
- data/spec/nonblocking_server_spec.rb +263 -0
- data/spec/processor_spec.rb +80 -0
- data/spec/serializer_spec.rb +67 -0
- data/spec/server_socket_spec.rb +79 -0
- data/spec/server_spec.rb +147 -0
- data/spec/socket_spec.rb +61 -0
- data/spec/socket_spec_shared.rb +104 -0
- data/spec/spec_helper.rb +64 -0
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +293 -0
- data/spec/thin_http_server_spec.rb +141 -0
- data/spec/types_spec.rb +115 -0
- data/spec/union_spec.rb +203 -0
- data/spec/unix_socket_spec.rb +107 -0
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +274 -0
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +761 -0
- data/test/debug_proto/gen-rb/empty_service.rb +24 -0
- data/test/debug_proto/gen-rb/inherited.rb +79 -0
- data/test/debug_proto/gen-rb/reverse_order_service.rb +82 -0
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +81 -0
- data/test/debug_proto/gen-rb/srv.rb +330 -0
- metadata +388 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 705d7f1ea6f2df5a1143b202d8d73897d2691ebb
|
4
|
+
data.tar.gz: 7f9bb47162ab72fe3a16b7ae40665225fb86a7ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f85f3a790e50117fb64706387de9cfc553c7b3c3e42d9bfecdd115d139e46f2f4d9c782643b6b8619a312801a85215e5c826c64bd31e57bd3c6cbcf7da0cf40
|
7
|
+
data.tar.gz: eb9d58c7f200fb7f082ebb51cad7733a2295c6ebec0b567e2be77281e1e644a69e5c51690ee379845ee53306774b51d3ae1bf744797ec185ca8c69e36b9e94f5
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Thrift Ruby Software Library
|
2
|
+
http://thrift.apache.org
|
3
|
+
|
4
|
+
== LICENSE:
|
5
|
+
|
6
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
7
|
+
or more contributor license agreements. See the NOTICE file
|
8
|
+
distributed with this work for additional information
|
9
|
+
regarding copyright ownership. The ASF licenses this file
|
10
|
+
to you under the Apache License, Version 2.0 (the
|
11
|
+
"License"); you may not use this file except in compliance
|
12
|
+
with the License. You may obtain a copy of the License at
|
13
|
+
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing,
|
17
|
+
software distributed under the License is distributed on an
|
18
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
19
|
+
KIND, either express or implied. See the License for the
|
20
|
+
specific language governing permissions and limitations
|
21
|
+
under the License.
|
22
|
+
|
23
|
+
== DESCRIPTION:
|
24
|
+
|
25
|
+
Thrift is a strongly-typed language-agnostic RPC system.
|
26
|
+
This library is the ruby implementation for both clients and servers.
|
27
|
+
|
28
|
+
== INSTALL:
|
29
|
+
|
30
|
+
$ gem install thrift
|
31
|
+
|
32
|
+
== CAVEATS:
|
33
|
+
|
34
|
+
This library provides the client and server implementations of thrift.
|
35
|
+
It does <em>not</em> provide the compiler for the .thrift files. To compile
|
36
|
+
.thrift files into language-specific implementations, please download the full
|
37
|
+
thrift software package.
|
38
|
+
|
39
|
+
== USAGE:
|
40
|
+
|
41
|
+
This section should get written by someone with the time and inclination.
|
42
|
+
In the meantime, look at existing code, such as the benchmark or the tutorial
|
43
|
+
in the full thrift distribution.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
namespace rb ThriftBenchmark
|
21
|
+
|
22
|
+
service BenchmarkService {
|
23
|
+
i32 fibonacci(1:byte n)
|
24
|
+
}
|
@@ -0,0 +1,271 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
22
|
+
require 'thrift'
|
23
|
+
require 'stringio'
|
24
|
+
|
25
|
+
HOST = '127.0.0.1'
|
26
|
+
PORT = 42587
|
27
|
+
|
28
|
+
###############
|
29
|
+
## Server
|
30
|
+
###############
|
31
|
+
|
32
|
+
class Server
|
33
|
+
attr_accessor :serverclass
|
34
|
+
attr_accessor :interpreter
|
35
|
+
attr_accessor :host
|
36
|
+
attr_accessor :port
|
37
|
+
|
38
|
+
def initialize(opts)
|
39
|
+
@serverclass = opts.fetch(:class, Thrift::NonblockingServer)
|
40
|
+
@interpreter = opts.fetch(:interpreter, "ruby")
|
41
|
+
@host = opts.fetch(:host, ::HOST)
|
42
|
+
@port = opts.fetch(:port, ::PORT)
|
43
|
+
end
|
44
|
+
|
45
|
+
def start
|
46
|
+
return if @serverclass == Object
|
47
|
+
args = (File.basename(@interpreter) == "jruby" ? "-J-server" : "")
|
48
|
+
@pipe = IO.popen("#{@interpreter} #{args} #{File.dirname(__FILE__)}/server.rb #{@host} #{@port} #{@serverclass.name}", "r+")
|
49
|
+
Marshal.load(@pipe) # wait until the server has started
|
50
|
+
sleep 0.4 # give the server time to actually start spawning sockets
|
51
|
+
end
|
52
|
+
|
53
|
+
def shutdown
|
54
|
+
return unless @pipe
|
55
|
+
Marshal.dump(:shutdown, @pipe)
|
56
|
+
begin
|
57
|
+
@pipe.read(10) # block until the server shuts down
|
58
|
+
rescue EOFError
|
59
|
+
end
|
60
|
+
@pipe.close
|
61
|
+
@pipe = nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class BenchmarkManager
|
66
|
+
def initialize(opts, server)
|
67
|
+
@socket = opts.fetch(:socket) do
|
68
|
+
@host = opts.fetch(:host, 'localhost')
|
69
|
+
@port = opts.fetch(:port)
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
@num_processes = opts.fetch(:num_processes, 40)
|
73
|
+
@clients_per_process = opts.fetch(:clients_per_process, 10)
|
74
|
+
@calls_per_client = opts.fetch(:calls_per_client, 50)
|
75
|
+
@interpreter = opts.fetch(:interpreter, "ruby")
|
76
|
+
@server = server
|
77
|
+
@log_exceptions = opts.fetch(:log_exceptions, false)
|
78
|
+
end
|
79
|
+
|
80
|
+
def run
|
81
|
+
@pool = []
|
82
|
+
@benchmark_start = Time.now
|
83
|
+
puts "Spawning benchmark processes..."
|
84
|
+
@num_processes.times do
|
85
|
+
spawn
|
86
|
+
sleep 0.02 # space out spawns
|
87
|
+
end
|
88
|
+
collect_output
|
89
|
+
@benchmark_end = Time.now # we know the procs are done here
|
90
|
+
translate_output
|
91
|
+
analyze_output
|
92
|
+
report_output
|
93
|
+
end
|
94
|
+
|
95
|
+
def spawn
|
96
|
+
pipe = IO.popen("#{@interpreter} #{File.dirname(__FILE__)}/client.rb #{"-log-exceptions" if @log_exceptions} #{@host} #{@port} #{@clients_per_process} #{@calls_per_client}")
|
97
|
+
@pool << pipe
|
98
|
+
end
|
99
|
+
|
100
|
+
def socket_class
|
101
|
+
if @socket
|
102
|
+
Thrift::UNIXSocket
|
103
|
+
else
|
104
|
+
Thrift::Socket
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def collect_output
|
109
|
+
puts "Collecting output..."
|
110
|
+
# read from @pool until all sockets are closed
|
111
|
+
@buffers = Hash.new { |h,k| h[k] = '' }
|
112
|
+
until @pool.empty?
|
113
|
+
rd, = select(@pool)
|
114
|
+
next if rd.nil?
|
115
|
+
rd.each do |fd|
|
116
|
+
begin
|
117
|
+
@buffers[fd] << fd.readpartial(4096)
|
118
|
+
rescue EOFError
|
119
|
+
@pool.delete fd
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def translate_output
|
126
|
+
puts "Translating output..."
|
127
|
+
@output = []
|
128
|
+
@buffers.each do |fd, buffer|
|
129
|
+
strio = StringIO.new(buffer)
|
130
|
+
logs = []
|
131
|
+
begin
|
132
|
+
loop do
|
133
|
+
logs << Marshal.load(strio)
|
134
|
+
end
|
135
|
+
rescue EOFError
|
136
|
+
@output << logs
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def analyze_output
|
142
|
+
puts "Analyzing output..."
|
143
|
+
call_times = []
|
144
|
+
client_times = []
|
145
|
+
connection_failures = []
|
146
|
+
connection_errors = []
|
147
|
+
shortest_call = 0
|
148
|
+
shortest_client = 0
|
149
|
+
longest_call = 0
|
150
|
+
longest_client = 0
|
151
|
+
@output.each do |logs|
|
152
|
+
cur_call, cur_client = nil
|
153
|
+
logs.each do |tok, time|
|
154
|
+
case tok
|
155
|
+
when :start
|
156
|
+
cur_client = time
|
157
|
+
when :call_start
|
158
|
+
cur_call = time
|
159
|
+
when :call_end
|
160
|
+
delta = time - cur_call
|
161
|
+
call_times << delta
|
162
|
+
longest_call = delta unless longest_call > delta
|
163
|
+
shortest_call = delta if shortest_call == 0 or delta < shortest_call
|
164
|
+
cur_call = nil
|
165
|
+
when :end
|
166
|
+
delta = time - cur_client
|
167
|
+
client_times << delta
|
168
|
+
longest_client = delta unless longest_client > delta
|
169
|
+
shortest_client = delta if shortest_client == 0 or delta < shortest_client
|
170
|
+
cur_client = nil
|
171
|
+
when :connection_failure
|
172
|
+
connection_failures << time
|
173
|
+
when :connection_error
|
174
|
+
connection_errors << time
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
@report = {}
|
179
|
+
@report[:total_calls] = call_times.inject(0.0) { |a,t| a += t }
|
180
|
+
@report[:avg_calls] = @report[:total_calls] / call_times.size
|
181
|
+
@report[:total_clients] = client_times.inject(0.0) { |a,t| a += t }
|
182
|
+
@report[:avg_clients] = @report[:total_clients] / client_times.size
|
183
|
+
@report[:connection_failures] = connection_failures.size
|
184
|
+
@report[:connection_errors] = connection_errors.size
|
185
|
+
@report[:shortest_call] = shortest_call
|
186
|
+
@report[:shortest_client] = shortest_client
|
187
|
+
@report[:longest_call] = longest_call
|
188
|
+
@report[:longest_client] = longest_client
|
189
|
+
@report[:total_benchmark_time] = @benchmark_end - @benchmark_start
|
190
|
+
@report[:fastthread] = $".include?('fastthread.bundle')
|
191
|
+
end
|
192
|
+
|
193
|
+
def report_output
|
194
|
+
fmt = "%.4f seconds"
|
195
|
+
puts
|
196
|
+
tabulate "%d",
|
197
|
+
[["Server class", "%s"], @server.serverclass == Object ? "" : @server.serverclass],
|
198
|
+
[["Server interpreter", "%s"], @server.interpreter],
|
199
|
+
[["Client interpreter", "%s"], @interpreter],
|
200
|
+
[["Socket class", "%s"], socket_class],
|
201
|
+
["Number of processes", @num_processes],
|
202
|
+
["Clients per process", @clients_per_process],
|
203
|
+
["Calls per client", @calls_per_client],
|
204
|
+
[["Using fastthread", "%s"], @report[:fastthread] ? "yes" : "no"]
|
205
|
+
puts
|
206
|
+
failures = (@report[:connection_failures] > 0)
|
207
|
+
tabulate fmt,
|
208
|
+
[["Connection failures", "%d", [:red, :bold]], @report[:connection_failures]],
|
209
|
+
[["Connection errors", "%d", [:red, :bold]], @report[:connection_errors]],
|
210
|
+
["Average time per call", @report[:avg_calls]],
|
211
|
+
["Average time per client (%d calls)" % @calls_per_client, @report[:avg_clients]],
|
212
|
+
["Total time for all calls", @report[:total_calls]],
|
213
|
+
["Real time for benchmarking", @report[:total_benchmark_time]],
|
214
|
+
["Shortest call time", @report[:shortest_call]],
|
215
|
+
["Longest call time", @report[:longest_call]],
|
216
|
+
["Shortest client time (%d calls)" % @calls_per_client, @report[:shortest_client]],
|
217
|
+
["Longest client time (%d calls)" % @calls_per_client, @report[:longest_client]]
|
218
|
+
end
|
219
|
+
|
220
|
+
ANSI = {
|
221
|
+
:reset => 0,
|
222
|
+
:bold => 1,
|
223
|
+
:black => 30,
|
224
|
+
:red => 31,
|
225
|
+
:green => 32,
|
226
|
+
:yellow => 33,
|
227
|
+
:blue => 34,
|
228
|
+
:magenta => 35,
|
229
|
+
:cyan => 36,
|
230
|
+
:white => 37
|
231
|
+
}
|
232
|
+
|
233
|
+
def tabulate(fmt, *labels_and_values)
|
234
|
+
labels = labels_and_values.map { |l| Array === l ? l.first : l }
|
235
|
+
label_width = labels.inject(0) { |w,l| l.size > w ? l.size : w }
|
236
|
+
labels_and_values.each do |(l,v)|
|
237
|
+
f = fmt
|
238
|
+
l, f, c = l if Array === l
|
239
|
+
fmtstr = "%-#{label_width+1}s #{f}"
|
240
|
+
if STDOUT.tty? and c and v.to_i > 0
|
241
|
+
fmtstr = "\e[#{[*c].map { |x| ANSI[x] } * ";"}m" + fmtstr + "\e[#{ANSI[:reset]}m"
|
242
|
+
end
|
243
|
+
puts fmtstr % [l+":", v]
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def resolve_const(const)
|
249
|
+
const and const.split('::').inject(Object) { |k,c| k.const_get(c) }
|
250
|
+
end
|
251
|
+
|
252
|
+
puts "Starting server..."
|
253
|
+
args = {}
|
254
|
+
args[:interpreter] = ENV['THRIFT_SERVER_INTERPRETER'] || ENV['THRIFT_INTERPRETER'] || "ruby"
|
255
|
+
args[:class] = resolve_const(ENV['THRIFT_SERVER']) || Thrift::NonblockingServer
|
256
|
+
args[:host] = ENV['THRIFT_HOST'] || HOST
|
257
|
+
args[:port] = (ENV['THRIFT_PORT'] || PORT).to_i
|
258
|
+
server = Server.new(args)
|
259
|
+
server.start
|
260
|
+
|
261
|
+
args = {}
|
262
|
+
args[:host] = ENV['THRIFT_HOST'] || HOST
|
263
|
+
args[:port] = (ENV['THRIFT_PORT'] || PORT).to_i
|
264
|
+
args[:num_processes] = (ENV['THRIFT_NUM_PROCESSES'] || 40).to_i
|
265
|
+
args[:clients_per_process] = (ENV['THRIFT_NUM_CLIENTS'] || 5).to_i
|
266
|
+
args[:calls_per_client] = (ENV['THRIFT_NUM_CALLS'] || 50).to_i
|
267
|
+
args[:interpreter] = ENV['THRIFT_CLIENT_INTERPRETER'] || ENV['THRIFT_INTERPRETER'] || "ruby"
|
268
|
+
args[:log_exceptions] = !!ENV['THRIFT_LOG_EXCEPTIONS']
|
269
|
+
BenchmarkManager.new(args, server).run
|
270
|
+
|
271
|
+
server.shutdown
|
data/benchmark/client.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
21
|
+
require 'thrift'
|
22
|
+
$:.unshift File.dirname(__FILE__) + "/gen-rb"
|
23
|
+
require 'benchmark_service'
|
24
|
+
|
25
|
+
class Client
|
26
|
+
def initialize(host, port, clients_per_process, calls_per_client, log_exceptions)
|
27
|
+
@host = host
|
28
|
+
@port = port
|
29
|
+
@clients_per_process = clients_per_process
|
30
|
+
@calls_per_client = calls_per_client
|
31
|
+
@log_exceptions = log_exceptions
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
@clients_per_process.times do
|
36
|
+
socket = Thrift::Socket.new(@host, @port)
|
37
|
+
transport = Thrift::FramedTransport.new(socket)
|
38
|
+
protocol = Thrift::BinaryProtocol.new(transport)
|
39
|
+
client = ThriftBenchmark::BenchmarkService::Client.new(protocol)
|
40
|
+
begin
|
41
|
+
start = Time.now
|
42
|
+
transport.open
|
43
|
+
Marshal.dump [:start, start], STDOUT
|
44
|
+
rescue => e
|
45
|
+
Marshal.dump [:connection_failure, Time.now], STDOUT
|
46
|
+
print_exception e if @log_exceptions
|
47
|
+
else
|
48
|
+
begin
|
49
|
+
@calls_per_client.times do
|
50
|
+
Marshal.dump [:call_start, Time.now], STDOUT
|
51
|
+
client.fibonacci(15)
|
52
|
+
Marshal.dump [:call_end, Time.now], STDOUT
|
53
|
+
end
|
54
|
+
transport.close
|
55
|
+
Marshal.dump [:end, Time.now], STDOUT
|
56
|
+
rescue Thrift::TransportException => e
|
57
|
+
Marshal.dump [:connection_error, Time.now], STDOUT
|
58
|
+
print_exception e if @log_exceptions
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def print_exception(e)
|
65
|
+
STDERR.puts "ERROR: #{e.message}"
|
66
|
+
STDERR.puts "\t#{e.backtrace * "\n\t"}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
log_exceptions = true if ARGV[0] == '-log-exceptions' and ARGV.shift
|
71
|
+
|
72
|
+
host, port, clients_per_process, calls_per_client = ARGV
|
73
|
+
|
74
|
+
Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i, log_exceptions).run
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (1.0.0-upfluence)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
require 'benchmark_types'
|
9
|
+
|
10
|
+
module ThriftBenchmark
|
11
|
+
module BenchmarkService
|
12
|
+
class Client
|
13
|
+
include ::Thrift::Client
|
14
|
+
|
15
|
+
def fibonacci(n)
|
16
|
+
send_fibonacci(n)
|
17
|
+
return recv_fibonacci()
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_fibonacci(n)
|
21
|
+
send_message('fibonacci', Fibonacci_args, :n => n)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recv_fibonacci()
|
25
|
+
result = receive_message(Fibonacci_result)
|
26
|
+
return result.success unless result.success.nil?
|
27
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'fibonacci failed: unknown result')
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class Processor
|
33
|
+
include ::Thrift::Processor
|
34
|
+
|
35
|
+
def process_fibonacci(seqid, iprot, oprot)
|
36
|
+
args = read_args(iprot, Fibonacci_args)
|
37
|
+
result = Fibonacci_result.new()
|
38
|
+
result.success = @handler.fibonacci(args.n)
|
39
|
+
write_result(result, oprot, 'fibonacci', seqid)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
45
|
+
|
46
|
+
class Fibonacci_args
|
47
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
48
|
+
N = 1
|
49
|
+
|
50
|
+
FIELDS = {
|
51
|
+
N => {:type => ::Thrift::Types::BYTE, :name => 'n'}
|
52
|
+
}
|
53
|
+
|
54
|
+
def struct_fields; FIELDS; end
|
55
|
+
|
56
|
+
def validate
|
57
|
+
end
|
58
|
+
|
59
|
+
::Thrift::Struct.generate_accessors self
|
60
|
+
end
|
61
|
+
|
62
|
+
class Fibonacci_result
|
63
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
64
|
+
SUCCESS = 0
|
65
|
+
|
66
|
+
FIELDS = {
|
67
|
+
SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success'}
|
68
|
+
}
|
69
|
+
|
70
|
+
def struct_fields; FIELDS; end
|
71
|
+
|
72
|
+
def validate
|
73
|
+
end
|
74
|
+
|
75
|
+
::Thrift::Struct.generate_accessors self
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|