-
-
Save takeshiyako2/f8d8c6e1fc87dd6bd920 to your computer and use it in GitHub Desktop.
PHP require performance
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
#!/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