thrift 0.24.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.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -4
  3. data/ext/binary_protocol_accelerated.c +52 -17
  4. data/ext/compact_protocol.c +135 -70
  5. data/ext/constants.h +3 -0
  6. data/ext/extconf.rb +4 -4
  7. data/ext/macros.h +11 -0
  8. data/ext/memory_buffer.c +35 -17
  9. data/ext/struct.c +185 -64
  10. data/ext/thrift_native.c +6 -0
  11. data/lib/thrift/bytes.rb +2 -2
  12. data/lib/thrift/client.rb +31 -22
  13. data/lib/thrift/exceptions.rb +10 -8
  14. data/lib/thrift/multiplexed_processor.rb +5 -6
  15. data/lib/thrift/processor.rb +24 -3
  16. data/lib/thrift/protocol/base_protocol.rb +53 -27
  17. data/lib/thrift/protocol/binary_protocol.rb +54 -40
  18. data/lib/thrift/protocol/binary_protocol_accelerated.rb +6 -2
  19. data/lib/thrift/protocol/compact_protocol.rb +193 -88
  20. data/lib/thrift/protocol/header_protocol.rb +14 -3
  21. data/lib/thrift/protocol/json_protocol.rb +146 -104
  22. data/lib/thrift/protocol/multiplexed_protocol.rb +2 -3
  23. data/lib/thrift/protocol/protocol_decorator.rb +5 -2
  24. data/lib/thrift/serializer/serializer.rb +6 -0
  25. data/lib/thrift/server/base_server.rb +10 -2
  26. data/lib/thrift/server/nonblocking_server.rb +49 -26
  27. data/lib/thrift/server/rack_application.rb +69 -0
  28. data/lib/thrift/server/simple_server.rb +27 -23
  29. data/lib/thrift/server/thin_http_server.rb +20 -44
  30. data/lib/thrift/server/thread_pool_server.rb +20 -17
  31. data/lib/thrift/server/threaded_server.rb +22 -26
  32. data/lib/thrift/struct.rb +33 -18
  33. data/lib/thrift/struct_union.rb +36 -30
  34. data/lib/thrift/transport/base_transport.rb +23 -5
  35. data/lib/thrift/transport/buffered_transport.rb +4 -4
  36. data/lib/thrift/transport/framed_transport.rb +32 -7
  37. data/lib/thrift/transport/header_transport.rb +130 -50
  38. data/lib/thrift/transport/http_client_transport.rb +27 -14
  39. data/lib/thrift/transport/io_stream_transport.rb +2 -1
  40. data/lib/thrift/transport/memory_buffer_transport.rb +8 -10
  41. data/lib/thrift/transport/server_socket.rb +4 -5
  42. data/lib/thrift/transport/socket.rb +20 -22
  43. data/lib/thrift/transport/ssl_server_socket.rb +64 -4
  44. data/lib/thrift/transport/ssl_socket.rb +32 -5
  45. data/lib/thrift/transport/unix_server_socket.rb +1 -1
  46. data/lib/thrift/transport/unix_socket.rb +4 -6
  47. data/lib/thrift/types.rb +22 -22
  48. data/lib/thrift/union.rb +20 -11
  49. data/lib/thrift/uuid.rb +8 -8
  50. data/lib/thrift.rb +39 -39
  51. metadata +5 -230
  52. data/benchmark/Benchmark.thrift +0 -24
  53. data/benchmark/benchmark.rb +0 -286
  54. data/benchmark/client.rb +0 -118
  55. data/benchmark/server.rb +0 -121
  56. data/benchmark/thin_server.rb +0 -46
  57. data/lib/thrift/server/mongrel_http_server.rb +0 -61
  58. data/spec/BaseService.thrift +0 -27
  59. data/spec/ExtendedService.thrift +0 -25
  60. data/spec/Referenced.thrift +0 -44
  61. data/spec/ThriftNamespacedSpec.thrift +0 -53
  62. data/spec/ThriftSpec.thrift +0 -203
  63. data/spec/base_protocol_spec.rb +0 -244
  64. data/spec/base_transport_spec.rb +0 -428
  65. data/spec/binary_protocol_accelerated_spec.rb +0 -47
  66. data/spec/binary_protocol_spec.rb +0 -73
  67. data/spec/binary_protocol_spec_shared.rb +0 -509
  68. data/spec/bytes_spec.rb +0 -117
  69. data/spec/client_spec.rb +0 -167
  70. data/spec/compact_protocol_spec.rb +0 -295
  71. data/spec/constants_demo_spec.rb +0 -102
  72. data/spec/exception_spec.rb +0 -141
  73. data/spec/flat_spec.rb +0 -63
  74. data/spec/header_protocol_spec.rb +0 -476
  75. data/spec/header_transport_spec.rb +0 -431
  76. data/spec/http_client_spec.rb +0 -160
  77. data/spec/json_protocol_spec.rb +0 -574
  78. data/spec/multiplexed_processor_spec.rb +0 -75
  79. data/spec/namespaced_spec.rb +0 -67
  80. data/spec/nonblocking_server_spec.rb +0 -429
  81. data/spec/processor_spec.rb +0 -80
  82. data/spec/recursion_depth_spec.rb +0 -223
  83. data/spec/serializer_spec.rb +0 -67
  84. data/spec/server_socket_spec.rb +0 -121
  85. data/spec/server_spec.rb +0 -238
  86. data/spec/socket_spec.rb +0 -174
  87. data/spec/socket_spec_shared.rb +0 -168
  88. data/spec/spec_helper.rb +0 -70
  89. data/spec/ssl_server_socket_spec.rb +0 -85
  90. data/spec/ssl_socket_spec.rb +0 -248
  91. data/spec/struct_nested_containers_spec.rb +0 -191
  92. data/spec/struct_spec.rb +0 -398
  93. data/spec/support/header_protocol_helper.rb +0 -55
  94. data/spec/thin_http_server_spec.rb +0 -127
  95. data/spec/types_spec.rb +0 -118
  96. data/spec/union_spec.rb +0 -273
  97. data/spec/unix_socket_spec.rb +0 -131
  98. data/spec/uuid_validation_spec.rb +0 -239
  99. data/test/fuzz/Makefile +0 -779
  100. data/test/fuzz/Makefile.am +0 -173
  101. data/test/fuzz/Makefile.in +0 -775
  102. data/test/fuzz/README.md +0 -149
  103. data/test/fuzz/fuzz_common.rb +0 -96
  104. data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -23
  105. data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -23
  106. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -23
  107. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -23
  108. data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -23
  109. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -23
  110. data/test/fuzz/fuzz_parse_json_protocol.rb +0 -23
  111. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -23
  112. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -23
  113. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -23
  114. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -23
  115. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -23
  116. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -23
  117. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -23
  118. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -23
  119. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -23
  120. data/test/fuzz/fuzz_tracer.rb +0 -29
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apache Thrift Developers
@@ -93,34 +93,6 @@ dependencies:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
95
  version: '3.7'
96
- - !ruby/object:Gem::Dependency
97
- name: srv
98
- requirement: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '1.0'
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '1.0'
110
- - !ruby/object:Gem::Dependency
111
- name: thin
112
- requirement: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '1.7'
117
- type: :development
118
- prerelease: false
119
- version_requirements: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - "~>"
122
- - !ruby/object:Gem::Version
123
- version: '1.7'
124
96
  description: Ruby bindings for the Apache Thrift RPC system
125
97
  email:
126
98
  - dev@thrift.apache.org
@@ -129,74 +101,8 @@ extensions:
129
101
  - ext/extconf.rb
130
102
  extra_rdoc_files:
131
103
  - README.md
132
- - ext/binary_protocol_accelerated.c
133
- - ext/binary_protocol_accelerated.h
134
- - ext/bytes.c
135
- - ext/bytes.h
136
- - ext/compact_protocol.c
137
- - ext/compact_protocol.h
138
- - ext/constants.h
139
- - ext/extconf.rb
140
- - ext/macros.h
141
- - ext/memory_buffer.c
142
- - ext/memory_buffer.h
143
- - ext/protocol.c
144
- - ext/protocol.h
145
- - ext/strlcpy.c
146
- - ext/strlcpy.h
147
- - ext/struct.c
148
- - ext/struct.h
149
- - ext/thrift_native.c
150
- - lib/thrift.rb
151
- - lib/thrift/bytes.rb
152
- - lib/thrift/client.rb
153
- - lib/thrift/exceptions.rb
154
- - lib/thrift/multiplexed_processor.rb
155
- - lib/thrift/processor.rb
156
- - lib/thrift/protocol/base_protocol.rb
157
- - lib/thrift/protocol/binary_protocol.rb
158
- - lib/thrift/protocol/binary_protocol_accelerated.rb
159
- - lib/thrift/protocol/compact_protocol.rb
160
- - lib/thrift/protocol/header_protocol.rb
161
- - lib/thrift/protocol/json_protocol.rb
162
- - lib/thrift/protocol/multiplexed_protocol.rb
163
- - lib/thrift/protocol/protocol_decorator.rb
164
- - lib/thrift/serializer/deserializer.rb
165
- - lib/thrift/serializer/serializer.rb
166
- - lib/thrift/server/base_server.rb
167
- - lib/thrift/server/mongrel_http_server.rb
168
- - lib/thrift/server/nonblocking_server.rb
169
- - lib/thrift/server/simple_server.rb
170
- - lib/thrift/server/thin_http_server.rb
171
- - lib/thrift/server/thread_pool_server.rb
172
- - lib/thrift/server/threaded_server.rb
173
- - lib/thrift/struct.rb
174
- - lib/thrift/struct_union.rb
175
- - lib/thrift/thrift_native.rb
176
- - lib/thrift/transport/base_server_transport.rb
177
- - lib/thrift/transport/base_transport.rb
178
- - lib/thrift/transport/buffered_transport.rb
179
- - lib/thrift/transport/framed_transport.rb
180
- - lib/thrift/transport/header_transport.rb
181
- - lib/thrift/transport/http_client_transport.rb
182
- - lib/thrift/transport/io_stream_transport.rb
183
- - lib/thrift/transport/memory_buffer_transport.rb
184
- - lib/thrift/transport/server_socket.rb
185
- - lib/thrift/transport/socket.rb
186
- - lib/thrift/transport/ssl_server_socket.rb
187
- - lib/thrift/transport/ssl_socket.rb
188
- - lib/thrift/transport/unix_server_socket.rb
189
- - lib/thrift/transport/unix_socket.rb
190
- - lib/thrift/types.rb
191
- - lib/thrift/union.rb
192
- - lib/thrift/uuid.rb
193
104
  files:
194
105
  - README.md
195
- - benchmark/Benchmark.thrift
196
- - benchmark/benchmark.rb
197
- - benchmark/client.rb
198
- - benchmark/server.rb
199
- - benchmark/thin_server.rb
200
106
  - ext/binary_protocol_accelerated.c
201
107
  - ext/binary_protocol_accelerated.h
202
108
  - ext/bytes.c
@@ -232,8 +138,8 @@ files:
232
138
  - lib/thrift/serializer/deserializer.rb
233
139
  - lib/thrift/serializer/serializer.rb
234
140
  - lib/thrift/server/base_server.rb
235
- - lib/thrift/server/mongrel_http_server.rb
236
141
  - lib/thrift/server/nonblocking_server.rb
142
+ - lib/thrift/server/rack_application.rb
237
143
  - lib/thrift/server/simple_server.rb
238
144
  - lib/thrift/server/thin_http_server.rb
239
145
  - lib/thrift/server/thread_pool_server.rb
@@ -258,69 +164,6 @@ files:
258
164
  - lib/thrift/types.rb
259
165
  - lib/thrift/union.rb
260
166
  - lib/thrift/uuid.rb
261
- - spec/BaseService.thrift
262
- - spec/ExtendedService.thrift
263
- - spec/Referenced.thrift
264
- - spec/ThriftNamespacedSpec.thrift
265
- - spec/ThriftSpec.thrift
266
- - spec/base_protocol_spec.rb
267
- - spec/base_transport_spec.rb
268
- - spec/binary_protocol_accelerated_spec.rb
269
- - spec/binary_protocol_spec.rb
270
- - spec/binary_protocol_spec_shared.rb
271
- - spec/bytes_spec.rb
272
- - spec/client_spec.rb
273
- - spec/compact_protocol_spec.rb
274
- - spec/constants_demo_spec.rb
275
- - spec/exception_spec.rb
276
- - spec/flat_spec.rb
277
- - spec/header_protocol_spec.rb
278
- - spec/header_transport_spec.rb
279
- - spec/http_client_spec.rb
280
- - spec/json_protocol_spec.rb
281
- - spec/multiplexed_processor_spec.rb
282
- - spec/namespaced_spec.rb
283
- - spec/nonblocking_server_spec.rb
284
- - spec/processor_spec.rb
285
- - spec/recursion_depth_spec.rb
286
- - spec/serializer_spec.rb
287
- - spec/server_socket_spec.rb
288
- - spec/server_spec.rb
289
- - spec/socket_spec.rb
290
- - spec/socket_spec_shared.rb
291
- - spec/spec_helper.rb
292
- - spec/ssl_server_socket_spec.rb
293
- - spec/ssl_socket_spec.rb
294
- - spec/struct_nested_containers_spec.rb
295
- - spec/struct_spec.rb
296
- - spec/support/header_protocol_helper.rb
297
- - spec/thin_http_server_spec.rb
298
- - spec/types_spec.rb
299
- - spec/union_spec.rb
300
- - spec/unix_socket_spec.rb
301
- - spec/uuid_validation_spec.rb
302
- - test/fuzz/Makefile
303
- - test/fuzz/Makefile.am
304
- - test/fuzz/Makefile.in
305
- - test/fuzz/README.md
306
- - test/fuzz/fuzz_common.rb
307
- - test/fuzz/fuzz_parse_binary_protocol.rb
308
- - test/fuzz/fuzz_parse_binary_protocol_accelerated.rb
309
- - test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb
310
- - test/fuzz/fuzz_parse_binary_protocol_harness.rb
311
- - test/fuzz/fuzz_parse_compact_protocol.rb
312
- - test/fuzz/fuzz_parse_compact_protocol_harness.rb
313
- - test/fuzz/fuzz_parse_json_protocol.rb
314
- - test/fuzz/fuzz_parse_json_protocol_harness.rb
315
- - test/fuzz/fuzz_roundtrip_binary_protocol.rb
316
- - test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb
317
- - test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb
318
- - test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb
319
- - test/fuzz/fuzz_roundtrip_compact_protocol.rb
320
- - test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb
321
- - test/fuzz/fuzz_roundtrip_json_protocol.rb
322
- - test/fuzz/fuzz_roundtrip_json_protocol_harness.rb
323
- - test/fuzz/fuzz_tracer.rb
324
167
  homepage: https://thrift.apache.org
325
168
  licenses:
326
169
  - Apache-2.0
@@ -345,82 +188,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
345
188
  requirements:
346
189
  - - ">="
347
190
  - !ruby/object:Gem::Version
348
- version: 2.7.0
191
+ version: 3.0.0
349
192
  required_rubygems_version: !ruby/object:Gem::Requirement
350
193
  requirements:
351
194
  - - ">="
352
195
  - !ruby/object:Gem::Version
353
196
  version: '0'
354
197
  requirements: []
355
- rubygems_version: 3.6.7
198
+ rubygems_version: 4.0.20
356
199
  specification_version: 4
357
200
  summary: Ruby bindings for Apache Thrift
358
- test_files:
359
- - benchmark/Benchmark.thrift
360
- - benchmark/benchmark.rb
361
- - benchmark/client.rb
362
- - benchmark/server.rb
363
- - benchmark/thin_server.rb
364
- - spec/BaseService.thrift
365
- - spec/ExtendedService.thrift
366
- - spec/Referenced.thrift
367
- - spec/ThriftNamespacedSpec.thrift
368
- - spec/ThriftSpec.thrift
369
- - spec/base_protocol_spec.rb
370
- - spec/base_transport_spec.rb
371
- - spec/binary_protocol_accelerated_spec.rb
372
- - spec/binary_protocol_spec.rb
373
- - spec/binary_protocol_spec_shared.rb
374
- - spec/bytes_spec.rb
375
- - spec/client_spec.rb
376
- - spec/compact_protocol_spec.rb
377
- - spec/constants_demo_spec.rb
378
- - spec/exception_spec.rb
379
- - spec/flat_spec.rb
380
- - spec/header_protocol_spec.rb
381
- - spec/header_transport_spec.rb
382
- - spec/http_client_spec.rb
383
- - spec/json_protocol_spec.rb
384
- - spec/multiplexed_processor_spec.rb
385
- - spec/namespaced_spec.rb
386
- - spec/nonblocking_server_spec.rb
387
- - spec/processor_spec.rb
388
- - spec/recursion_depth_spec.rb
389
- - spec/serializer_spec.rb
390
- - spec/server_socket_spec.rb
391
- - spec/server_spec.rb
392
- - spec/socket_spec.rb
393
- - spec/socket_spec_shared.rb
394
- - spec/spec_helper.rb
395
- - spec/ssl_server_socket_spec.rb
396
- - spec/ssl_socket_spec.rb
397
- - spec/struct_nested_containers_spec.rb
398
- - spec/struct_spec.rb
399
- - spec/support/header_protocol_helper.rb
400
- - spec/thin_http_server_spec.rb
401
- - spec/types_spec.rb
402
- - spec/union_spec.rb
403
- - spec/unix_socket_spec.rb
404
- - spec/uuid_validation_spec.rb
405
- - test/fuzz/Makefile
406
- - test/fuzz/Makefile.am
407
- - test/fuzz/Makefile.in
408
- - test/fuzz/README.md
409
- - test/fuzz/fuzz_common.rb
410
- - test/fuzz/fuzz_parse_binary_protocol.rb
411
- - test/fuzz/fuzz_parse_binary_protocol_accelerated.rb
412
- - test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb
413
- - test/fuzz/fuzz_parse_binary_protocol_harness.rb
414
- - test/fuzz/fuzz_parse_compact_protocol.rb
415
- - test/fuzz/fuzz_parse_compact_protocol_harness.rb
416
- - test/fuzz/fuzz_parse_json_protocol.rb
417
- - test/fuzz/fuzz_parse_json_protocol_harness.rb
418
- - test/fuzz/fuzz_roundtrip_binary_protocol.rb
419
- - test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb
420
- - test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb
421
- - test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb
422
- - test/fuzz/fuzz_roundtrip_compact_protocol.rb
423
- - test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb
424
- - test/fuzz/fuzz_roundtrip_json_protocol.rb
425
- - test/fuzz/fuzz_roundtrip_json_protocol_harness.rb
426
- - test/fuzz/fuzz_tracer.rb
201
+ test_files: []
@@ -1,24 +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
- namespace rb ThriftBenchmark
21
-
22
- service BenchmarkService {
23
- i32 fibonacci(1:byte n)
24
- }
@@ -1,286 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'rubygems'
22
- $:.unshift File.dirname(__FILE__) + '/../lib'
23
- $:.unshift File.dirname(__FILE__) + '/../ext'
24
- require 'thrift'
25
- require 'stringio'
26
-
27
- HOST = '127.0.0.1'
28
- PORT = 42587
29
-
30
- ###############
31
- ## Server
32
- ###############
33
-
34
- class Server
35
- attr_accessor :serverclass
36
- attr_accessor :interpreter
37
- attr_accessor :host
38
- attr_accessor :port
39
- attr_accessor :protocol_type
40
-
41
- def initialize(opts)
42
- @serverclass = opts.fetch(:class, Thrift::NonblockingServer)
43
- @interpreter = opts.fetch(:interpreter, "ruby")
44
- @host = opts.fetch(:host, ::HOST)
45
- @port = opts.fetch(:port, ::PORT)
46
- @protocol_type = opts.fetch(:protocol_type, 'binary')
47
- @tls = opts.fetch(:tls, false)
48
- end
49
-
50
- def start
51
- return if @serverclass == Object
52
- args = (File.basename(@interpreter) == "jruby" ? "-J-server" : "")
53
- @pipe = IO.popen("#{@interpreter} #{args} #{File.dirname(__FILE__)}/server.rb #{"-tls" if @tls} #{@host} #{@port} #{@serverclass.name} #{@protocol_type}", "r+")
54
- Marshal.load(@pipe) # wait until the server has started
55
- sleep 0.4 # give the server time to actually start spawning sockets
56
- end
57
-
58
- def shutdown
59
- return unless @pipe
60
- Marshal.dump(:shutdown, @pipe)
61
- begin
62
- @pipe.read(10) # block until the server shuts down
63
- rescue EOFError
64
- end
65
- @pipe.close
66
- @pipe = nil
67
- end
68
- end
69
-
70
- class BenchmarkManager
71
- def initialize(opts, server)
72
- @socket = opts.fetch(:socket) do
73
- @host = opts.fetch(:host, 'localhost')
74
- @port = opts.fetch(:port)
75
- nil
76
- end
77
- @num_processes = opts.fetch(:num_processes, 40)
78
- @clients_per_process = opts.fetch(:clients_per_process, 10)
79
- @calls_per_client = opts.fetch(:calls_per_client, 50)
80
- @interpreter = opts.fetch(:interpreter, "ruby")
81
- @server = server
82
- @log_exceptions = opts.fetch(:log_exceptions, false)
83
- @protocol_type = opts.fetch(:protocol_type, 'binary')
84
- @tls = opts.fetch(:tls, false)
85
- end
86
-
87
- def run
88
- @pool = []
89
- @benchmark_start = Time.now
90
- puts "Spawning benchmark processes..."
91
- @num_processes.times do
92
- spawn
93
- sleep 0.02 # space out spawns
94
- end
95
- collect_output
96
- @benchmark_end = Time.now # we know the procs are done here
97
- translate_output
98
- analyze_output
99
- report_output
100
- end
101
-
102
- def spawn
103
- 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}")
104
- @pool << pipe
105
- end
106
-
107
- def socket_class
108
- if @socket
109
- Thrift::UNIXSocket
110
- elsif @tls
111
- Thrift::SSLSocket
112
- else
113
- Thrift::Socket
114
- end
115
- end
116
-
117
- def collect_output
118
- puts "Collecting output..."
119
- # read from @pool until all sockets are closed
120
- @buffers = Hash.new { |h, k| h[k] = ''.b }
121
- until @pool.empty?
122
- rd, = select(@pool)
123
- next if rd.nil?
124
- rd.each do |fd|
125
- begin
126
- @buffers[fd] << fd.readpartial(4096)
127
- rescue EOFError
128
- @pool.delete fd
129
- end
130
- end
131
- end
132
- end
133
-
134
- def translate_output
135
- puts "Translating output..."
136
- @output = []
137
- @buffers.each do |fd, buffer|
138
- strio = StringIO.new(buffer)
139
- logs = []
140
- begin
141
- loop do
142
- logs << Marshal.load(strio)
143
- end
144
- rescue EOFError
145
- @output << logs
146
- end
147
- end
148
- end
149
-
150
- def analyze_output
151
- puts "Analyzing output..."
152
- call_times = []
153
- client_times = []
154
- connection_failures = []
155
- connection_errors = []
156
- shortest_call = 0
157
- shortest_client = 0
158
- longest_call = 0
159
- longest_client = 0
160
- @output.each do |logs|
161
- cur_call, cur_client = nil
162
- logs.each do |tok, time|
163
- case tok
164
- when :start
165
- cur_client = time
166
- when :call_start
167
- cur_call = time
168
- when :call_end
169
- delta = time - cur_call
170
- call_times << delta
171
- longest_call = delta unless longest_call > delta
172
- shortest_call = delta if shortest_call == 0 or delta < shortest_call
173
- cur_call = nil
174
- when :end
175
- delta = time - cur_client
176
- client_times << delta
177
- longest_client = delta unless longest_client > delta
178
- shortest_client = delta if shortest_client == 0 or delta < shortest_client
179
- cur_client = nil
180
- when :connection_failure
181
- connection_failures << time
182
- when :connection_error
183
- connection_errors << time
184
- end
185
- end
186
- end
187
- @report = {}
188
- @report[:total_calls] = call_times.inject(0.0) { |a, t| a += t }
189
- @report[:avg_calls] = @report[:total_calls] / call_times.size
190
- @report[:total_clients] = client_times.inject(0.0) { |a, t| a += t }
191
- @report[:avg_clients] = @report[:total_clients] / client_times.size
192
- @report[:connection_failures] = connection_failures.size
193
- @report[:connection_errors] = connection_errors.size
194
- @report[:shortest_call] = shortest_call
195
- @report[:shortest_client] = shortest_client
196
- @report[:longest_call] = longest_call
197
- @report[:longest_client] = longest_client
198
- @report[:total_benchmark_time] = @benchmark_end - @benchmark_start
199
- @report[:fastthread] = $".include?('fastthread.bundle')
200
- end
201
-
202
- def report_output
203
- fmt = "%.4f seconds"
204
- puts
205
- tabulate "%d",
206
- [["Server class", "%s"], @server.serverclass == Object ? "" : @server.serverclass],
207
- [["Server interpreter", "%s"], @server.interpreter],
208
- [["Client interpreter", "%s"], @interpreter],
209
- [["Protocol type", "%s"], @protocol_type],
210
- [["Socket class", "%s"], socket_class],
211
- ["Number of processes", @num_processes],
212
- ["Clients per process", @clients_per_process],
213
- ["Calls per client", @calls_per_client],
214
- [["Using fastthread", "%s"], @report[:fastthread] ? "yes" : "no"]
215
- puts
216
- failures = (@report[:connection_failures] > 0)
217
- tabulate fmt,
218
- [["Connection failures", "%d", [:red, :bold]], @report[:connection_failures]],
219
- [["Connection errors", "%d", [:red, :bold]], @report[:connection_errors]],
220
- ["Average time per call", @report[:avg_calls]],
221
- ["Average time per client (%d calls)" % @calls_per_client, @report[:avg_clients]],
222
- ["Total time for all calls", @report[:total_calls]],
223
- ["Real time for benchmarking", @report[:total_benchmark_time]],
224
- ["Shortest call time", @report[:shortest_call]],
225
- ["Longest call time", @report[:longest_call]],
226
- ["Shortest client time (%d calls)" % @calls_per_client, @report[:shortest_client]],
227
- ["Longest client time (%d calls)" % @calls_per_client, @report[:longest_client]]
228
- end
229
-
230
- ANSI = {
231
- :reset => 0,
232
- :bold => 1,
233
- :black => 30,
234
- :red => 31,
235
- :green => 32,
236
- :yellow => 33,
237
- :blue => 34,
238
- :magenta => 35,
239
- :cyan => 36,
240
- :white => 37
241
- }
242
-
243
- def tabulate(fmt, *labels_and_values)
244
- labels = labels_and_values.map { |l| Array === l ? l.first : l }
245
- label_width = labels.inject(0) { |w, l| l.size > w ? l.size : w }
246
- labels_and_values.each do |(l, v)|
247
- f = fmt
248
- l, f, c = l if Array === l
249
- fmtstr = "%-#{label_width+1}s #{f}"
250
- if STDOUT.tty? and c and v.to_i > 0
251
- fmtstr = "\e[#{[*c].map { |x| ANSI[x] } * ";"}m" + fmtstr + "\e[#{ANSI[:reset]}m"
252
- end
253
- puts fmtstr % [l+":", v]
254
- end
255
- end
256
- end
257
-
258
- def resolve_const(const)
259
- const and const.split('::').inject(Object) { |k, c| k.const_get(c) }
260
- end
261
-
262
- puts "Starting server..."
263
- protocol_type = ENV['THRIFT_PROTOCOL'] || 'binary'
264
- args = {}
265
- args[:interpreter] = ENV['THRIFT_SERVER_INTERPRETER'] || ENV['THRIFT_INTERPRETER'] || "ruby"
266
- args[:class] = resolve_const(ENV['THRIFT_SERVER']) || Thrift::NonblockingServer
267
- args[:host] = ENV['THRIFT_HOST'] || HOST
268
- args[:port] = (ENV['THRIFT_PORT'] || PORT).to_i
269
- args[:tls] = ENV['THRIFT_TLS'] == 'true'
270
- args[:protocol_type] = protocol_type
271
- server = Server.new(args)
272
- server.start
273
-
274
- args = {}
275
- args[:host] = ENV['THRIFT_HOST'] || HOST
276
- args[:port] = (ENV['THRIFT_PORT'] || PORT).to_i
277
- args[:tls] = ENV['THRIFT_TLS'] == 'true'
278
- args[:num_processes] = (ENV['THRIFT_NUM_PROCESSES'] || 40).to_i
279
- args[:clients_per_process] = (ENV['THRIFT_NUM_CLIENTS'] || 5).to_i
280
- args[:calls_per_client] = (ENV['THRIFT_NUM_CALLS'] || 50).to_i
281
- args[:interpreter] = ENV['THRIFT_CLIENT_INTERPRETER'] || ENV['THRIFT_INTERPRETER'] || "ruby"
282
- args[:log_exceptions] = !!ENV['THRIFT_LOG_EXCEPTIONS']
283
- args[:protocol_type] = protocol_type
284
- BenchmarkManager.new(args, server).run
285
-
286
- server.shutdown