Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the concept of transports to the client library in anticipation of
adding fibered em as a transport but also redis / 0mq based transports. Also added benchmark
- Loading branch information
Tobias Lütke
committed
Mar 26, 2011
1 parent
e94cdda
commit c0c890c
Showing
3 changed files
with
78 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'client' | ||
require 'benchmark' | ||
|
||
expectations = [] | ||
|
||
# Make rand predictable | ||
srand(0) | ||
|
||
# Build a series of 5000 tests, every test has format [expectation, method, *args] | ||
expectations = (0..5000).collect do | ||
case rand(3) | ||
when 0 | ||
num = rand(1000000) | ||
[num+num, :add, num, num] | ||
when 1 | ||
['hello', :hi] | ||
when 2 | ||
data = '.' * rand(10000) | ||
[data, :echo, data] | ||
end | ||
end | ||
|
||
# Create 5 concurrent workers to pound the server with the fuzz test | ||
pids = (0..4).collect do | ||
fork do | ||
socket = MessagePipe.new(TcpTransport.new('localhost', 9191)) | ||
|
||
|
||
ms = Benchmark.realtime do | ||
expectations.each do |expectation, method, *args| | ||
raise 'fail' unless socket.call(method, *args) == expectation | ||
end | ||
end | ||
|
||
puts "benchmark finished in #{ms}s" | ||
exit 0 | ||
|
||
end | ||
end | ||
|
||
# Wait for all forks to complete | ||
Process.waitall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,11 @@ def hi | |
'hello' | ||
end | ||
|
||
def echo(string) | ||
string | ||
end | ||
|
||
|
||
def throw | ||
raise StandardError, 'hell' | ||
end | ||
|