Create a gist now

Instantly share code, notes, and snippets.

@takeshiyako2 /run_test.rb Secret
Last active Sep 9, 2015

PHP require performance
#!/usr/bin/ruby
require 'systemu'
# www root dir
dir = '/var/h2o'
index = <<"EOS"
<?php
print 1;
EOS
require = <<"EOS"
<?php
return true;
EOS
# make index.php
index_file = "#{dir}/index.php"
File.write(index_file, index)
for i in 1..1000
require_file = "#{dir}/require#{i}.php"
# add require to index
File.open(index_file,"a") do |file|
file.write("require \'#{require_file}\';\n")
end
# make require file
File.write(require_file, require)
# check load av
status, stdout, stderr = systemu "w"
load_av = stdout.scan(/load average: (.*)/)[0][0]
# restart php-fpm & warm-ups
status, stdout, stderr = systemu "service php-fpm restart"
status, stdout, stderr = systemu "ab -c 10 -n 10000 http://localhost/"
sleep 20;
# run ab
req_p_s_array = []
for j in 1..3
status, stdout, stderr = systemu "ab -c 10 -n 10000 http://localhost/"
req_p_s = stdout.scan(/Requests per second:\s+(\d+)/)[0][0]
req_p_s_array << req_p_s.to_i
sleep 20;
end
average = (req_p_s_array.inject(0.0){|r,i| r+=i } / req_p_s_array.size).round
puts "#{i}\t#{average}\t#{req_p_s_array}\t#{load_av}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment