在本地测试并发的最好方法是什么?也就是说,我想测试10个并发命中。我知道像Blitz这样的服务。然而,我正在尝试找到一种更简单的方法来在本地测试竞态条件。
有什么想法吗?也许是通过Curl?
发布于 2012-08-14 10:21:31
查看Apache Bench (ab)。基本用法非常简单:
ab -n 100 -c 10 http://your.application发布于 2012-08-14 14:55:48
为了在本地测试测试中的竞态条件,您可以使用这样的帮助器
# call block in a forked process
def fork_with_new_connection(config, object = nil, options={})
raise ArgumentError, "Missing block" unless block_given?
options = {
:stop => true, :index => 0
}.merge(options)
fork do
# stop the process after fork
Signal.trap('STOP') if options[:stop]
begin
ActiveRecord::Base.establish_connection(config)
yield(object)
ensure
ActiveRecord::Base.remove_connection
end
end
end
# call multiply times blocks
def multi_times_call_in_fork(count=3, &block)
raise ArgumentError, "Missing block" unless block_given?
config = ActiveRecord::Base.remove_connection
pids = []
count.times do |index|
pids << fork_with_new_connection(config, nil, :index=>index, &block)
end
# continue forked processes
Process.kill("CONT", *pids)
Process.waitall
ActiveRecord::Base.establish_connection(config)
end
# example
multi_times_call_in_fork(5) do
# do something with race conditions
# add asserts
end https://stackoverflow.com/questions/11944869
复制相似问题