public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Search Repo:
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
- Add a benchmark for socket connections versus persistent pipes.
- The unix_sockets_vs_pipes benchmark now shows the processed lines per 
second.
FooBarWidget (author)
Fri Feb 01 01:56:38 -0800 2008
commit  598ebedf9003a7310bb22ad09d18ec03823b067f
tree    78584cb6912ba555ef3d47c0ce62e4ae76f931d8
parent  4bc5f59d77baa0ef1dc0a2e8a2b809d4e531fb23
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
0
@@ -1 +1,90 @@
0
+#!/usr/bin/env ruby
0
+require 'benchmark'
0
+
0
+ITERATIONS = 100000
0
+MESSAGE = " " * 512
0
+MESSAGE_SIZE = [MESSAGE.size].pack('n')
0
+
0
+def start
0
+ if ARGV.empty?
0
+ benchmark_unix_sockets
0
+ benchmark_persistent_pipes
0
+ elsif ARGV.size == 1 && ARGV[0] == 'unix_sockets'
0
+ benchmark_unix_sockets
0
+ elsif ARGV.size == 1 && ARGV[0] == 'pipes'
0
+ benchmark_persistent_pipes
0
+ else
0
+ puts "Benchmarks performance ."
0
+ puts "Usage: socket_connections_vs_persistent_pipes.rb <unix_sockets|pipes>"
0
+ exit(1)
0
+ end
0
+end
0
+
0
+def benchmark_unix_sockets
0
+ require 'socket'
0
+ begin
0
+ puts "Benchmarking socket connections..."
0
+ File.unlink("benchmark.socket") rescue nil
0
+ pid = fork do
0
+ server = UNIXServer.new("benchmark.socket")
0
+ ITERATIONS.times do
0
+ client = server.accept
0
+ size = client.read(2).unpack('n')[0]
0
+ client.read(size)
0
+ client.write(MESSAGE)
0
+ client.close
0
+ end
0
+ server.close
0
+ end
0
+ result = Benchmark.measure do
0
+ ITERATIONS.times do
0
+ conn = UNIXSocket.new("benchmark.socket")
0
+ conn.write(MESSAGE_SIZE)
0
+ conn.write(MESSAGE)
0
+ conn.read
0
+ conn.close
0
+ end
0
+ end
0
+ Process.waitpid(pid)
0
+ puts "User/system/real time: #{result}"
0
+ printf "%.2f messages per second\n", ITERATIONS / result.real
0
+ ensure
0
+ File.unlink("benchmark.socket") rescue nil
0
+ end
0
+end
0
+
0
+def benchmark_persistent_pipes
0
+ puts "Benchmarking pipes connections..."
0
+ reader1, writer1 = IO.pipe
0
+ reader2, writer2 = IO.pipe
0
+ pid = fork do
0
+ reader1.close
0
+ writer2.close
0
+ reader = reader2
0
+ writer = writer1
0
+ ITERATIONS.times do
0
+ size = reader.read(2).unpack('n')[0]
0
+ reader.read(size)
0
+ writer.write(MESSAGE_SIZE)
0
+ writer.write(MESSAGE)
0
+ end
0
+ end
0
+ reader2.close
0
+ writer1.close
0
+ reader = reader1
0
+ writer = writer2
0
+ result = Benchmark.measure do
0
+ ITERATIONS.times do
0
+ writer.write(MESSAGE_SIZE)
0
+ writer.write(MESSAGE)
0
+ size = reader.read(2).unpack('n')[0]
0
+ reader.read(size)
0
+ end
0
+ end
0
+ Process.waitpid(pid)
0
+ puts "User/system/real time: #{result}"
0
+ printf "%.2f messages per second\n", ITERATIONS / result.real
0
+end
0
+
0
+start
...
1
 
2
3
 
 
4
5
6
...
10
11
12
13
 
14
15
16
...
25
26
27
28
 
29
30
31
...
36
37
38
 
39
40
41
...
1
2
3
4
5
6
7
8
9
...
13
14
15
 
16
17
18
19
...
28
29
30
 
31
32
33
34
...
39
40
41
42
43
44
45
0
@@ -1,6 +1,9 @@
0
 #!/usr/bin/env ruby
0
+# Benchmarks raw Unix socket I/O performance versus pipe I/O performance.
0
 require 'benchmark'
0
 
0
+ITERATIONS = 150000
0
+
0
 def start
0
   if ARGV.empty?
0
     benchmark(:unix_sockets)
0
@@ -10,7 +13,7 @@
0
   elsif ARGV.size == 1 && ARGV[0] == 'pipes'
0
     benchmark(:pipes)
0
   else
0
- puts "Benchmarks Unix socket performance versus pipe performance."
0
+ puts "Benchmarks raw Unix socket I/O performance versus pipe I/O performance."
0
     puts "Usage: unix_sockets_vs_pipes.rb <unix_sockets|pipes>"
0
     exit(1)
0
   end
0
@@ -25,7 +28,7 @@
0
     pid, reader, writer = setup_pipes
0
   end
0
   result = Benchmark.measure do
0
- 150000.times do |i|
0
+ ITERATIONS.times do |i|
0
       writer.write("hello world\n")
0
       reader.readline
0
     end
0
@@ -36,6 +39,7 @@
0
     Process.waitpid(pid)
0
   end
0
   puts "User/system/real time: #{result}"
0
+ printf "%.2f lines per second\n", ITERATIONS / result.real
0
 end
0
 
0
 def setup_unix_sockets

Comments

    No one has commented yet.