服务器端
用phpg写了一个小页面,软件是用nginx+fastcgi,spawn-fcgi设置-C 为 20,启动20个进程,这样在多线程测试才有效,不然就是一个php cgi进程上面的队列,必须等第一个请求完成,第二个请求才会处理
php页面代码
rub测试端
require 'open-uri' s = Time.now puts s 10.times do open("http://localhost/index.php") end e = Time.now puts e puts "no thread #{e -s}" threads = [] s = Time.now puts s 10.times do threads.push(Thread.new{ open("http://localhost/index.php") }) end while true threads.each {|t| if t.alive? Thread.pass break else threads.delete t end } break if threads.length < 1 end e = Time.now puts e puts "thread #{e -s}"
测试结果,不用线程耗时30秒,启动10个线程,耗时3秒