thrift 0.23.0 → 0.25.0
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.
- checksums.yaml +4 -4
- data/README.md +203 -40
- data/ext/binary_protocol_accelerated.c +130 -40
- data/ext/bytes.c +14 -0
- data/ext/compact_protocol.c +184 -91
- data/ext/constants.h +3 -0
- data/ext/extconf.rb +12 -4
- data/ext/macros.h +11 -0
- data/ext/memory_buffer.c +67 -12
- data/ext/struct.c +192 -71
- data/ext/thrift_native.c +7 -0
- data/lib/thrift/bytes.rb +6 -3
- data/lib/thrift/client.rb +31 -33
- data/lib/thrift/exceptions.rb +11 -8
- data/lib/thrift/multiplexed_processor.rb +17 -8
- data/lib/thrift/processor.rb +25 -3
- data/lib/thrift/protocol/base_protocol.rb +66 -31
- data/lib/thrift/protocol/binary_protocol.rb +80 -37
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +7 -2
- data/lib/thrift/protocol/compact_protocol.rb +204 -88
- data/lib/thrift/protocol/header_protocol.rb +15 -3
- data/lib/thrift/protocol/json_protocol.rb +158 -109
- data/lib/thrift/protocol/multiplexed_protocol.rb +3 -3
- data/lib/thrift/protocol/protocol_decorator.rb +6 -2
- data/lib/thrift/serializer/deserializer.rb +1 -0
- data/lib/thrift/serializer/serializer.rb +7 -0
- data/lib/thrift/server/base_server.rb +11 -2
- data/lib/thrift/server/nonblocking_server.rb +69 -20
- data/lib/thrift/server/rack_application.rb +69 -0
- data/lib/thrift/server/simple_server.rb +27 -15
- data/lib/thrift/server/thin_http_server.rb +21 -44
- data/lib/thrift/server/thread_pool_server.rb +21 -17
- data/lib/thrift/server/threaded_server.rb +22 -18
- data/lib/thrift/struct.rb +34 -18
- data/lib/thrift/struct_union.rb +37 -36
- data/lib/thrift/thrift_native.rb +2 -1
- data/lib/thrift/transport/base_server_transport.rb +3 -0
- data/lib/thrift/transport/base_transport.rb +26 -4
- data/lib/thrift/transport/buffered_transport.rb +5 -4
- data/lib/thrift/transport/framed_transport.rb +33 -7
- data/lib/thrift/transport/header_transport.rb +159 -33
- data/lib/thrift/transport/http_client_transport.rb +28 -14
- data/lib/thrift/transport/io_stream_transport.rb +3 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +14 -9
- data/lib/thrift/transport/server_socket.rb +10 -8
- data/lib/thrift/transport/socket.rb +85 -48
- data/lib/thrift/transport/ssl_server_socket.rb +67 -6
- data/lib/thrift/transport/ssl_socket.rb +73 -14
- data/lib/thrift/transport/unix_server_socket.rb +6 -2
- data/lib/thrift/transport/unix_socket.rb +5 -6
- data/lib/thrift/types.rb +23 -22
- data/lib/thrift/union.rb +21 -11
- data/lib/thrift/uuid.rb +9 -8
- data/lib/thrift.rb +40 -39
- metadata +7 -266
- data/benchmark/Benchmark.thrift +0 -24
- data/benchmark/benchmark.rb +0 -285
- data/benchmark/client.rb +0 -117
- data/benchmark/server.rb +0 -120
- data/benchmark/thin_server.rb +0 -45
- data/lib/thrift/server/mongrel_http_server.rb +0 -60
- data/spec/BaseService.thrift +0 -27
- data/spec/ExtendedService.thrift +0 -25
- data/spec/Referenced.thrift +0 -44
- data/spec/ThriftNamespacedSpec.thrift +0 -53
- data/spec/ThriftSpec.thrift +0 -187
- data/spec/base_protocol_spec.rb +0 -224
- data/spec/base_transport_spec.rb +0 -387
- data/spec/binary_protocol_accelerated_spec.rb +0 -46
- data/spec/binary_protocol_spec.rb +0 -72
- data/spec/binary_protocol_spec_shared.rb +0 -445
- data/spec/bytes_spec.rb +0 -99
- data/spec/client_spec.rb +0 -166
- data/spec/compact_protocol_spec.rb +0 -196
- data/spec/constants_demo_spec.rb +0 -101
- data/spec/exception_spec.rb +0 -140
- data/spec/flat_spec.rb +0 -62
- data/spec/header_protocol_spec.rb +0 -475
- data/spec/header_transport_spec.rb +0 -386
- data/spec/http_client_spec.rb +0 -159
- data/spec/json_protocol_spec.rb +0 -552
- data/spec/namespaced_spec.rb +0 -66
- data/spec/nonblocking_server_spec.rb +0 -361
- data/spec/processor_spec.rb +0 -79
- data/spec/serializer_spec.rb +0 -66
- data/spec/server_socket_spec.rb +0 -84
- data/spec/server_spec.rb +0 -186
- data/spec/socket_spec.rb +0 -67
- data/spec/socket_spec_shared.rb +0 -167
- data/spec/spec_helper.rb +0 -69
- data/spec/ssl_server_socket_spec.rb +0 -45
- data/spec/ssl_socket_spec.rb +0 -87
- data/spec/struct_nested_containers_spec.rb +0 -190
- data/spec/struct_spec.rb +0 -397
- data/spec/support/header_protocol_helper.rb +0 -54
- data/spec/thin_http_server_spec.rb +0 -126
- data/spec/types_spec.rb +0 -117
- data/spec/union_spec.rb +0 -272
- data/spec/unix_socket_spec.rb +0 -115
- data/spec/uuid_validation_spec.rb +0 -238
- data/test/fuzz/Makefile.am +0 -173
- data/test/fuzz/README.md +0 -149
- data/test/fuzz/fuzz_common.rb +0 -95
- data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_json_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_tracer.rb +0 -28
data/benchmark/benchmark.rb
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
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
|
-
$:.unshift File.dirname(__FILE__) + '/../ext'
|
|
23
|
-
require 'thrift'
|
|
24
|
-
require 'stringio'
|
|
25
|
-
|
|
26
|
-
HOST = '127.0.0.1'
|
|
27
|
-
PORT = 42587
|
|
28
|
-
|
|
29
|
-
###############
|
|
30
|
-
## Server
|
|
31
|
-
###############
|
|
32
|
-
|
|
33
|
-
class Server
|
|
34
|
-
attr_accessor :serverclass
|
|
35
|
-
attr_accessor :interpreter
|
|
36
|
-
attr_accessor :host
|
|
37
|
-
attr_accessor :port
|
|
38
|
-
attr_accessor :protocol_type
|
|
39
|
-
|
|
40
|
-
def initialize(opts)
|
|
41
|
-
@serverclass = opts.fetch(:class, Thrift::NonblockingServer)
|
|
42
|
-
@interpreter = opts.fetch(:interpreter, "ruby")
|
|
43
|
-
@host = opts.fetch(:host, ::HOST)
|
|
44
|
-
@port = opts.fetch(:port, ::PORT)
|
|
45
|
-
@protocol_type = opts.fetch(:protocol_type, 'binary')
|
|
46
|
-
@tls = opts.fetch(:tls, false)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def start
|
|
50
|
-
return if @serverclass == Object
|
|
51
|
-
args = (File.basename(@interpreter) == "jruby" ? "-J-server" : "")
|
|
52
|
-
@pipe = IO.popen("#{@interpreter} #{args} #{File.dirname(__FILE__)}/server.rb #{"-tls" if @tls} #{@host} #{@port} #{@serverclass.name} #{@protocol_type}", "r+")
|
|
53
|
-
Marshal.load(@pipe) # wait until the server has started
|
|
54
|
-
sleep 0.4 # give the server time to actually start spawning sockets
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def shutdown
|
|
58
|
-
return unless @pipe
|
|
59
|
-
Marshal.dump(:shutdown, @pipe)
|
|
60
|
-
begin
|
|
61
|
-
@pipe.read(10) # block until the server shuts down
|
|
62
|
-
rescue EOFError
|
|
63
|
-
end
|
|
64
|
-
@pipe.close
|
|
65
|
-
@pipe = nil
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
class BenchmarkManager
|
|
70
|
-
def initialize(opts, server)
|
|
71
|
-
@socket = opts.fetch(:socket) do
|
|
72
|
-
@host = opts.fetch(:host, 'localhost')
|
|
73
|
-
@port = opts.fetch(:port)
|
|
74
|
-
nil
|
|
75
|
-
end
|
|
76
|
-
@num_processes = opts.fetch(:num_processes, 40)
|
|
77
|
-
@clients_per_process = opts.fetch(:clients_per_process, 10)
|
|
78
|
-
@calls_per_client = opts.fetch(:calls_per_client, 50)
|
|
79
|
-
@interpreter = opts.fetch(:interpreter, "ruby")
|
|
80
|
-
@server = server
|
|
81
|
-
@log_exceptions = opts.fetch(:log_exceptions, false)
|
|
82
|
-
@protocol_type = opts.fetch(:protocol_type, 'binary')
|
|
83
|
-
@tls = opts.fetch(:tls, false)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def run
|
|
87
|
-
@pool = []
|
|
88
|
-
@benchmark_start = Time.now
|
|
89
|
-
puts "Spawning benchmark processes..."
|
|
90
|
-
@num_processes.times do
|
|
91
|
-
spawn
|
|
92
|
-
sleep 0.02 # space out spawns
|
|
93
|
-
end
|
|
94
|
-
collect_output
|
|
95
|
-
@benchmark_end = Time.now # we know the procs are done here
|
|
96
|
-
translate_output
|
|
97
|
-
analyze_output
|
|
98
|
-
report_output
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def spawn
|
|
102
|
-
pipe = IO.popen("#{@interpreter} #{File.dirname(__FILE__)}/client.rb #{"-log-exceptions" if @log_exceptions} #{"-tls" if @tls} #{@host} #{@port} #{@clients_per_process} #{@calls_per_client} #{@protocol_type}")
|
|
103
|
-
@pool << pipe
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def socket_class
|
|
107
|
-
if @socket
|
|
108
|
-
Thrift::UNIXSocket
|
|
109
|
-
elsif @tls
|
|
110
|
-
Thrift::SSLSocket
|
|
111
|
-
else
|
|
112
|
-
Thrift::Socket
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def collect_output
|
|
117
|
-
puts "Collecting output..."
|
|
118
|
-
# read from @pool until all sockets are closed
|
|
119
|
-
@buffers = Hash.new { |h, k| h[k] = '' }
|
|
120
|
-
until @pool.empty?
|
|
121
|
-
rd, = select(@pool)
|
|
122
|
-
next if rd.nil?
|
|
123
|
-
rd.each do |fd|
|
|
124
|
-
begin
|
|
125
|
-
@buffers[fd] << fd.readpartial(4096)
|
|
126
|
-
rescue EOFError
|
|
127
|
-
@pool.delete fd
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def translate_output
|
|
134
|
-
puts "Translating output..."
|
|
135
|
-
@output = []
|
|
136
|
-
@buffers.each do |fd, buffer|
|
|
137
|
-
strio = StringIO.new(buffer)
|
|
138
|
-
logs = []
|
|
139
|
-
begin
|
|
140
|
-
loop do
|
|
141
|
-
logs << Marshal.load(strio)
|
|
142
|
-
end
|
|
143
|
-
rescue EOFError
|
|
144
|
-
@output << logs
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def analyze_output
|
|
150
|
-
puts "Analyzing output..."
|
|
151
|
-
call_times = []
|
|
152
|
-
client_times = []
|
|
153
|
-
connection_failures = []
|
|
154
|
-
connection_errors = []
|
|
155
|
-
shortest_call = 0
|
|
156
|
-
shortest_client = 0
|
|
157
|
-
longest_call = 0
|
|
158
|
-
longest_client = 0
|
|
159
|
-
@output.each do |logs|
|
|
160
|
-
cur_call, cur_client = nil
|
|
161
|
-
logs.each do |tok, time|
|
|
162
|
-
case tok
|
|
163
|
-
when :start
|
|
164
|
-
cur_client = time
|
|
165
|
-
when :call_start
|
|
166
|
-
cur_call = time
|
|
167
|
-
when :call_end
|
|
168
|
-
delta = time - cur_call
|
|
169
|
-
call_times << delta
|
|
170
|
-
longest_call = delta unless longest_call > delta
|
|
171
|
-
shortest_call = delta if shortest_call == 0 or delta < shortest_call
|
|
172
|
-
cur_call = nil
|
|
173
|
-
when :end
|
|
174
|
-
delta = time - cur_client
|
|
175
|
-
client_times << delta
|
|
176
|
-
longest_client = delta unless longest_client > delta
|
|
177
|
-
shortest_client = delta if shortest_client == 0 or delta < shortest_client
|
|
178
|
-
cur_client = nil
|
|
179
|
-
when :connection_failure
|
|
180
|
-
connection_failures << time
|
|
181
|
-
when :connection_error
|
|
182
|
-
connection_errors << time
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
@report = {}
|
|
187
|
-
@report[:total_calls] = call_times.inject(0.0) { |a, t| a += t }
|
|
188
|
-
@report[:avg_calls] = @report[:total_calls] / call_times.size
|
|
189
|
-
@report[:total_clients] = client_times.inject(0.0) { |a, t| a += t }
|
|
190
|
-
@report[:avg_clients] = @report[:total_clients] / client_times.size
|
|
191
|
-
@report[:connection_failures] = connection_failures.size
|
|
192
|
-
@report[:connection_errors] = connection_errors.size
|
|
193
|
-
@report[:shortest_call] = shortest_call
|
|
194
|
-
@report[:shortest_client] = shortest_client
|
|
195
|
-
@report[:longest_call] = longest_call
|
|
196
|
-
@report[:longest_client] = longest_client
|
|
197
|
-
@report[:total_benchmark_time] = @benchmark_end - @benchmark_start
|
|
198
|
-
@report[:fastthread] = $".include?('fastthread.bundle')
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def report_output
|
|
202
|
-
fmt = "%.4f seconds"
|
|
203
|
-
puts
|
|
204
|
-
tabulate "%d",
|
|
205
|
-
[["Server class", "%s"], @server.serverclass == Object ? "" : @server.serverclass],
|
|
206
|
-
[["Server interpreter", "%s"], @server.interpreter],
|
|
207
|
-
[["Client interpreter", "%s"], @interpreter],
|
|
208
|
-
[["Protocol type", "%s"], @protocol_type],
|
|
209
|
-
[["Socket class", "%s"], socket_class],
|
|
210
|
-
["Number of processes", @num_processes],
|
|
211
|
-
["Clients per process", @clients_per_process],
|
|
212
|
-
["Calls per client", @calls_per_client],
|
|
213
|
-
[["Using fastthread", "%s"], @report[:fastthread] ? "yes" : "no"]
|
|
214
|
-
puts
|
|
215
|
-
failures = (@report[:connection_failures] > 0)
|
|
216
|
-
tabulate fmt,
|
|
217
|
-
[["Connection failures", "%d", [:red, :bold]], @report[:connection_failures]],
|
|
218
|
-
[["Connection errors", "%d", [:red, :bold]], @report[:connection_errors]],
|
|
219
|
-
["Average time per call", @report[:avg_calls]],
|
|
220
|
-
["Average time per client (%d calls)" % @calls_per_client, @report[:avg_clients]],
|
|
221
|
-
["Total time for all calls", @report[:total_calls]],
|
|
222
|
-
["Real time for benchmarking", @report[:total_benchmark_time]],
|
|
223
|
-
["Shortest call time", @report[:shortest_call]],
|
|
224
|
-
["Longest call time", @report[:longest_call]],
|
|
225
|
-
["Shortest client time (%d calls)" % @calls_per_client, @report[:shortest_client]],
|
|
226
|
-
["Longest client time (%d calls)" % @calls_per_client, @report[:longest_client]]
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
ANSI = {
|
|
230
|
-
:reset => 0,
|
|
231
|
-
:bold => 1,
|
|
232
|
-
:black => 30,
|
|
233
|
-
:red => 31,
|
|
234
|
-
:green => 32,
|
|
235
|
-
:yellow => 33,
|
|
236
|
-
:blue => 34,
|
|
237
|
-
:magenta => 35,
|
|
238
|
-
:cyan => 36,
|
|
239
|
-
:white => 37
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
def tabulate(fmt, *labels_and_values)
|
|
243
|
-
labels = labels_and_values.map { |l| Array === l ? l.first : l }
|
|
244
|
-
label_width = labels.inject(0) { |w, l| l.size > w ? l.size : w }
|
|
245
|
-
labels_and_values.each do |(l, v)|
|
|
246
|
-
f = fmt
|
|
247
|
-
l, f, c = l if Array === l
|
|
248
|
-
fmtstr = "%-#{label_width+1}s #{f}"
|
|
249
|
-
if STDOUT.tty? and c and v.to_i > 0
|
|
250
|
-
fmtstr = "\e[#{[*c].map { |x| ANSI[x] } * ";"}m" + fmtstr + "\e[#{ANSI[:reset]}m"
|
|
251
|
-
end
|
|
252
|
-
puts fmtstr % [l+":", v]
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
def resolve_const(const)
|
|
258
|
-
const and const.split('::').inject(Object) { |k, c| k.const_get(c) }
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
puts "Starting server..."
|
|
262
|
-
protocol_type = ENV['THRIFT_PROTOCOL'] || 'binary'
|
|
263
|
-
args = {}
|
|
264
|
-
args[:interpreter] = ENV['THRIFT_SERVER_INTERPRETER'] || ENV['THRIFT_INTERPRETER'] || "ruby"
|
|
265
|
-
args[:class] = resolve_const(ENV['THRIFT_SERVER']) || Thrift::NonblockingServer
|
|
266
|
-
args[:host] = ENV['THRIFT_HOST'] || HOST
|
|
267
|
-
args[:port] = (ENV['THRIFT_PORT'] || PORT).to_i
|
|
268
|
-
args[:tls] = ENV['THRIFT_TLS'] == 'true'
|
|
269
|
-
args[:protocol_type] = protocol_type
|
|
270
|
-
server = Server.new(args)
|
|
271
|
-
server.start
|
|
272
|
-
|
|
273
|
-
args = {}
|
|
274
|
-
args[:host] = ENV['THRIFT_HOST'] || HOST
|
|
275
|
-
args[:port] = (ENV['THRIFT_PORT'] || PORT).to_i
|
|
276
|
-
args[:tls] = ENV['THRIFT_TLS'] == 'true'
|
|
277
|
-
args[:num_processes] = (ENV['THRIFT_NUM_PROCESSES'] || 40).to_i
|
|
278
|
-
args[:clients_per_process] = (ENV['THRIFT_NUM_CLIENTS'] || 5).to_i
|
|
279
|
-
args[:calls_per_client] = (ENV['THRIFT_NUM_CALLS'] || 50).to_i
|
|
280
|
-
args[:interpreter] = ENV['THRIFT_CLIENT_INTERPRETER'] || ENV['THRIFT_INTERPRETER'] || "ruby"
|
|
281
|
-
args[:log_exceptions] = !!ENV['THRIFT_LOG_EXCEPTIONS']
|
|
282
|
-
args[:protocol_type] = protocol_type
|
|
283
|
-
BenchmarkManager.new(args, server).run
|
|
284
|
-
|
|
285
|
-
server.shutdown
|
data/benchmark/client.rb
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
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
|
-
$:.unshift File.dirname(__FILE__) + '/../ext'
|
|
22
|
-
require 'thrift'
|
|
23
|
-
require 'openssl'
|
|
24
|
-
$:.unshift File.dirname(__FILE__) + "/gen-rb"
|
|
25
|
-
require 'benchmark_service'
|
|
26
|
-
|
|
27
|
-
class Client
|
|
28
|
-
def initialize(host, port, clients_per_process, calls_per_client, log_exceptions, tls, protocol_type)
|
|
29
|
-
@host = host
|
|
30
|
-
@port = port
|
|
31
|
-
@clients_per_process = clients_per_process
|
|
32
|
-
@calls_per_client = calls_per_client
|
|
33
|
-
@log_exceptions = log_exceptions
|
|
34
|
-
@tls = tls
|
|
35
|
-
@protocol_type = protocol_type || 'binary'
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def create_protocol(socket)
|
|
39
|
-
case @protocol_type
|
|
40
|
-
when 'binary'
|
|
41
|
-
transport = Thrift::FramedTransport.new(socket)
|
|
42
|
-
Thrift::BinaryProtocol.new(transport)
|
|
43
|
-
when 'compact'
|
|
44
|
-
transport = Thrift::FramedTransport.new(socket)
|
|
45
|
-
Thrift::CompactProtocol.new(transport)
|
|
46
|
-
when 'header'
|
|
47
|
-
Thrift::HeaderProtocol.new(socket)
|
|
48
|
-
when 'header-compact'
|
|
49
|
-
Thrift::HeaderProtocol.new(socket, nil, Thrift::HeaderSubprotocolID::COMPACT)
|
|
50
|
-
when 'header-zlib'
|
|
51
|
-
protocol = Thrift::HeaderProtocol.new(socket)
|
|
52
|
-
protocol.add_transform(Thrift::HeaderTransformID::ZLIB)
|
|
53
|
-
protocol
|
|
54
|
-
else
|
|
55
|
-
transport = Thrift::FramedTransport.new(socket)
|
|
56
|
-
Thrift::BinaryProtocol.new(transport)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def run
|
|
61
|
-
@clients_per_process.times do
|
|
62
|
-
socket = if @tls
|
|
63
|
-
ssl_context = OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
|
64
|
-
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
65
|
-
ctx.min_version = OpenSSL::SSL::TLS1_2_VERSION
|
|
66
|
-
|
|
67
|
-
keys_dir = File.expand_path("../../../test/keys", __dir__)
|
|
68
|
-
ctx.ca_file = File.join(keys_dir, "CA.pem")
|
|
69
|
-
ctx.cert = OpenSSL::X509::Certificate.new(File.open(File.join(keys_dir, "client.crt")))
|
|
70
|
-
ctx.cert_store = OpenSSL::X509::Store.new
|
|
71
|
-
ctx.cert_store.add_file(File.join(keys_dir, 'server.pem'))
|
|
72
|
-
ctx.key = OpenSSL::PKey::RSA.new(File.open(File.join(keys_dir, "client.key")))
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
Thrift::SSLSocket.new(@host, @port, 5, ssl_context)
|
|
76
|
-
else
|
|
77
|
-
Thrift::Socket.new(@host, @port, 5)
|
|
78
|
-
end
|
|
79
|
-
protocol = create_protocol(socket)
|
|
80
|
-
transport = protocol.trans
|
|
81
|
-
client = ThriftBenchmark::BenchmarkService::Client.new(protocol)
|
|
82
|
-
begin
|
|
83
|
-
start = Time.now
|
|
84
|
-
transport.open
|
|
85
|
-
Marshal.dump [:start, start], STDOUT
|
|
86
|
-
rescue => e
|
|
87
|
-
Marshal.dump [:connection_failure, Time.now], STDOUT
|
|
88
|
-
print_exception e if @log_exceptions
|
|
89
|
-
else
|
|
90
|
-
begin
|
|
91
|
-
@calls_per_client.times do
|
|
92
|
-
Marshal.dump [:call_start, Time.now], STDOUT
|
|
93
|
-
client.fibonacci(15)
|
|
94
|
-
Marshal.dump [:call_end, Time.now], STDOUT
|
|
95
|
-
end
|
|
96
|
-
transport.close
|
|
97
|
-
Marshal.dump [:end, Time.now], STDOUT
|
|
98
|
-
rescue Thrift::TransportException => e
|
|
99
|
-
Marshal.dump [:connection_error, Time.now], STDOUT
|
|
100
|
-
print_exception e if @log_exceptions
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def print_exception(e)
|
|
107
|
-
STDERR.puts "ERROR: #{e.message}"
|
|
108
|
-
STDERR.puts "\t#{e.backtrace * "\n\t"}"
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
log_exceptions = true if ARGV[0] == '-log-exceptions' and ARGV.shift
|
|
113
|
-
tls = true if ARGV[0] == '-tls' and ARGV.shift
|
|
114
|
-
|
|
115
|
-
host, port, clients_per_process, calls_per_client, protocol_type = ARGV
|
|
116
|
-
|
|
117
|
-
Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i, log_exceptions, tls, protocol_type).run
|
data/benchmark/server.rb
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
$:.unshift File.dirname(__FILE__) + '/../ext'
|
|
22
|
-
require 'thrift'
|
|
23
|
-
require 'openssl'
|
|
24
|
-
$:.unshift File.dirname(__FILE__) + "/gen-rb"
|
|
25
|
-
require 'benchmark_service'
|
|
26
|
-
|
|
27
|
-
module Server
|
|
28
|
-
include Thrift
|
|
29
|
-
|
|
30
|
-
class BenchmarkHandler
|
|
31
|
-
# 1-based index into the fibonacci sequence
|
|
32
|
-
def fibonacci(n)
|
|
33
|
-
seq = [1, 1]
|
|
34
|
-
3.upto(n) do
|
|
35
|
-
seq << seq[-1] + seq[-2]
|
|
36
|
-
end
|
|
37
|
-
seq[n-1] # n is 1-based
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def self.create_factories(protocol_type)
|
|
42
|
-
case protocol_type
|
|
43
|
-
when 'binary'
|
|
44
|
-
[FramedTransportFactory.new, BinaryProtocolFactory.new]
|
|
45
|
-
when 'compact'
|
|
46
|
-
[FramedTransportFactory.new, CompactProtocolFactory.new]
|
|
47
|
-
when 'header'
|
|
48
|
-
[HeaderTransportFactory.new, HeaderProtocolFactory.new]
|
|
49
|
-
when 'header-compact'
|
|
50
|
-
[HeaderTransportFactory.new, HeaderProtocolFactory.new(nil, HeaderSubprotocolID::COMPACT)]
|
|
51
|
-
when 'header-zlib'
|
|
52
|
-
# Note: Server doesn't add transforms - it mirrors client's transforms
|
|
53
|
-
[HeaderTransportFactory.new, HeaderProtocolFactory.new]
|
|
54
|
-
else
|
|
55
|
-
[FramedTransportFactory.new, BinaryProtocolFactory.new]
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def self.start_server(host, port, serverClass, tls, protocol_type = nil)
|
|
60
|
-
handler = BenchmarkHandler.new
|
|
61
|
-
processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
|
|
62
|
-
transport = if tls
|
|
63
|
-
ssl_context = OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
|
64
|
-
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
65
|
-
ctx.min_version = OpenSSL::SSL::TLS1_2_VERSION
|
|
66
|
-
|
|
67
|
-
keys_dir = File.expand_path("../../../test/keys", __dir__)
|
|
68
|
-
ctx.ca_file = File.join(keys_dir, "CA.pem")
|
|
69
|
-
ctx.cert = OpenSSL::X509::Certificate.new(File.open(File.join(keys_dir, "server.crt")))
|
|
70
|
-
ctx.cert_store = OpenSSL::X509::Store.new
|
|
71
|
-
ctx.cert_store.add_file(File.join(keys_dir, 'client.pem'))
|
|
72
|
-
ctx.key = OpenSSL::PKey::RSA.new(File.open(File.join(keys_dir, "server.key")))
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
Thrift::SSLServerSocket.new(host, port, ssl_context)
|
|
76
|
-
else
|
|
77
|
-
ServerSocket.new(host, port)
|
|
78
|
-
end
|
|
79
|
-
transport_factory, protocol_factory = create_factories(protocol_type || 'binary')
|
|
80
|
-
args = [processor, transport, transport_factory, protocol_factory, 20]
|
|
81
|
-
if serverClass == NonblockingServer
|
|
82
|
-
logger = Logger.new(STDERR)
|
|
83
|
-
logger.level = Logger::WARN
|
|
84
|
-
args << logger
|
|
85
|
-
end
|
|
86
|
-
server = serverClass.new(*args)
|
|
87
|
-
@server_thread = Thread.new do
|
|
88
|
-
server.serve
|
|
89
|
-
end
|
|
90
|
-
@server = server
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def self.shutdown
|
|
94
|
-
return if @server.nil?
|
|
95
|
-
if @server.respond_to? :shutdown
|
|
96
|
-
@server.shutdown
|
|
97
|
-
else
|
|
98
|
-
@server_thread.kill
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def resolve_const(const)
|
|
104
|
-
const and const.split('::').inject(Object) { |k, c| k.const_get(c) }
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
tls = true if ARGV[0] == '-tls' and ARGV.shift
|
|
108
|
-
|
|
109
|
-
host, port, serverklass, protocol_type = ARGV
|
|
110
|
-
|
|
111
|
-
Server.start_server(host, port.to_i, resolve_const(serverklass), tls, protocol_type)
|
|
112
|
-
|
|
113
|
-
# let our host know that the interpreter has started
|
|
114
|
-
# ideally we'd wait until the server was serving, but we don't have a hook for that
|
|
115
|
-
Marshal.dump(:started, STDOUT)
|
|
116
|
-
STDOUT.flush
|
|
117
|
-
|
|
118
|
-
Marshal.load(STDIN) # wait until we're instructed to shut down
|
|
119
|
-
|
|
120
|
-
Server.shutdown
|
data/benchmark/thin_server.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
$:.unshift File.dirname(__FILE__) + '/../ext'
|
|
22
|
-
require 'thrift'
|
|
23
|
-
$:.unshift File.dirname(__FILE__) + "/gen-rb"
|
|
24
|
-
require 'benchmark_service'
|
|
25
|
-
HOST = 'localhost'
|
|
26
|
-
PORT = 42587
|
|
27
|
-
|
|
28
|
-
class BenchmarkHandler
|
|
29
|
-
# 1-based index into the fibonacci sequence
|
|
30
|
-
def fibonacci(n)
|
|
31
|
-
seq = [1, 1]
|
|
32
|
-
3.upto(n) do
|
|
33
|
-
seq << seq[-1] + seq[-2]
|
|
34
|
-
end
|
|
35
|
-
seq[n-1] # n is 1-based
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
handler = BenchmarkHandler.new
|
|
40
|
-
processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
|
|
41
|
-
transport = Thrift::ServerSocket.new(HOST, PORT)
|
|
42
|
-
transport_factory = Thrift::FramedTransportFactory.new
|
|
43
|
-
logger = Logger.new(STDERR)
|
|
44
|
-
logger.level = Logger::WARN
|
|
45
|
-
Thrift::NonblockingServer.new(processor, transport, transport_factory, nil, 20, logger).serve
|
|
@@ -1,60 +0,0 @@
|
|
|
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 'mongrel'
|
|
21
|
-
|
|
22
|
-
## Sticks a service on a URL, using mongrel to do the HTTP work
|
|
23
|
-
# <b>DEPRECATED:</b> Please use <tt>Thrift::ThinHTTPServer</tt> instead.
|
|
24
|
-
module Thrift
|
|
25
|
-
class MongrelHTTPServer < BaseServer
|
|
26
|
-
class Handler < Mongrel::HttpHandler
|
|
27
|
-
def initialize(processor, protocol_factory)
|
|
28
|
-
@processor = processor
|
|
29
|
-
@protocol_factory = protocol_factory
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def process(request, response)
|
|
33
|
-
if request.params["REQUEST_METHOD"] == "POST"
|
|
34
|
-
response.start(200) do |head, out|
|
|
35
|
-
head["Content-Type"] = "application/x-thrift"
|
|
36
|
-
transport = IOStreamTransport.new request.body, out
|
|
37
|
-
protocol = @protocol_factory.get_protocol transport
|
|
38
|
-
@processor.process protocol, protocol
|
|
39
|
-
end
|
|
40
|
-
else
|
|
41
|
-
response.start(404) {}
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def initialize(processor, opts = {})
|
|
47
|
-
Kernel.warn "[DEPRECATION WARNING] `Thrift::MongrelHTTPServer` is deprecated. Please use `Thrift::ThinHTTPServer` instead."
|
|
48
|
-
port = opts[:port] || 80
|
|
49
|
-
ip = opts[:ip] || "0.0.0.0"
|
|
50
|
-
path = opts[:path] || ""
|
|
51
|
-
protocol_factory = opts[:protocol_factory] || BinaryProtocolFactory.new
|
|
52
|
-
@server = Mongrel::HttpServer.new ip, port
|
|
53
|
-
@server.register "/#{path}", Handler.new(processor, protocol_factory)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def serve
|
|
57
|
-
@server.run.join
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
data/spec/BaseService.thrift
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
-
# or more contributor license agreements. See the NOTICE file
|
|
3
|
-
# distributed with this work for additional information
|
|
4
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
-
# to you under the Apache License, Version 2.0 (the
|
|
6
|
-
# "License"); you may not use this file except in compliance
|
|
7
|
-
# with the License. You may obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing,
|
|
12
|
-
# software distributed under the License is distributed on an
|
|
13
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
# KIND, either express or implied. See the License for the
|
|
15
|
-
# specific language governing permissions and limitations
|
|
16
|
-
# under the License.
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
namespace rb Base
|
|
20
|
-
|
|
21
|
-
struct Hello {
|
|
22
|
-
1: string greeting = "hello world"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
service BaseService {
|
|
26
|
-
Hello greeting(1:bool english)
|
|
27
|
-
}
|
data/spec/ExtendedService.thrift
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
-
# or more contributor license agreements. See the NOTICE file
|
|
3
|
-
# distributed with this work for additional information
|
|
4
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
-
# to you under the Apache License, Version 2.0 (the
|
|
6
|
-
# "License"); you may not use this file except in compliance
|
|
7
|
-
# with the License. You may obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing,
|
|
12
|
-
# software distributed under the License is distributed on an
|
|
13
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
# KIND, either express or implied. See the License for the
|
|
15
|
-
# specific language governing permissions and limitations
|
|
16
|
-
# under the License.
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
namespace rb Extended
|
|
20
|
-
|
|
21
|
-
include "BaseService.thrift"
|
|
22
|
-
|
|
23
|
-
service ExtendedService extends BaseService.BaseService {
|
|
24
|
-
void ping()
|
|
25
|
-
}
|