Sha256: 0ef3bc139b14c6f2245117ec98925a7ed4af38dba61d3fc039132fd71473eb3b

Contents?: true

Size: 1.72 KB

Versions: 35

Compression:

Stored size: 1.72 KB

Contents

#!/usr/bin/env ruby
require 'benchmark'
require 'socket'

ITERATIONS = 100000
REQUEST = " " * 800
REQUEST_SIZE = REQUEST.size
RESPONSE = " " * 5 * 1024
RESPONSE_SIZE = RESPONSE.size
PASSWORD = "x" * 128
PASSWORD_SIZE = PASSWORD.size

def start
	benchmark_with_password_checking
	puts ""
	benchmark_without_password_checking
end

def benchmark_with_password_checking
	puts "Benchmarking with password checking..."
	parent, child = UNIXSocket.pair
	pid = fork do
		parent.close
		ITERATIONS.times do
			password = child.read(PASSWORD_SIZE)
			if password == PASSWORD
				child.read(REQUEST_SIZE)
				child.write(RESPONSE)
				# This flush here improves performance significantly!
				child.flush
			else
				child.close
				break
			end
		end
	end
	child.close
	
	result = Benchmark.measure do
		ITERATIONS.times do
			parent.write(PASSWORD)
			parent.write(REQUEST)
			parent.flush
			parent.read(RESPONSE_SIZE)
		end
	end
	parent.close
	Process.waitpid(pid)
	puts "User/system/real time: #{result}"
	printf "%.2f messages per second\n", ITERATIONS / result.real
end

def benchmark_without_password_checking
	puts "Benchmarking without password checking..."
	parent, child = UNIXSocket.pair
	pid = fork do
		parent.close
		ITERATIONS.times do
			child.read(REQUEST_SIZE)
			child.write(RESPONSE)
			# This flush here improves performance significantly!
			child.flush
		end
	end
	child.close
	
	result = Benchmark.measure do
		ITERATIONS.times do
			parent.write(REQUEST)
			# We do not call flush. For some reason it degrades performance.
			parent.read(RESPONSE_SIZE)
		end
	end
	parent.close
	Process.waitpid(pid)
	puts "Without password checking:"
	puts "User/system/real time: #{result}"
	printf "%.2f messages per second\n", ITERATIONS / result.real
end

start

Version data entries

35 entries across 35 versions & 5 rubygems

Version Path
passenger-1.0.2 benchmark/overhead_of_password_checking.rb
passenger-1.0.3 benchmark/overhead_of_password_checking.rb
passenger-1.0.4 benchmark/overhead_of_password_checking.rb
passenger-1.0.5 benchmark/overhead_of_password_checking.rb
passenger-2.0.1 benchmark/overhead_of_password_checking.rb
passenger-2.0.4 benchmark/overhead_of_password_checking.rb
passenger-2.0.2 benchmark/overhead_of_password_checking.rb
passenger-2.0.3 benchmark/overhead_of_password_checking.rb
passenger-2.0.6 benchmark/overhead_of_password_checking.rb
passenger-2.0.5 benchmark/overhead_of_password_checking.rb
passenger-2.1.2 benchmark/overhead_of_password_checking.rb
passenger-2.2.0 benchmark/overhead_of_password_checking.rb
passenger-2.1.3 benchmark/overhead_of_password_checking.rb
passenger-2.2.1 benchmark/overhead_of_password_checking.rb
passenger-2.2.2 benchmark/overhead_of_password_checking.rb