可能重复:
'ab'程序在很多请求后冻结,为什么?
这是一个简单的测试服务器:
require 'rubygems'
require 'rack'
require 'thin'
class HelloWorld
def call(env)
[200, {"Content-Type" => "text/plain"}, "OK"]
end
end
Rack::Handler::Thin.run HelloWorld.new, :Port => 9294
#I've tried with these added too, 'rack.multithread' => true, 'rack.multiprocess' => true
Run Code Online (Sandbox Code Playgroud)
这是一个测试运行:
$ ab -n 20000 http://0.0.0.0:9294/sdf
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 0.0.0.0 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed …Run Code Online (Sandbox Code Playgroud) puts [1,2,3].map do |x|
x + 1
end.inspect
Run Code Online (Sandbox Code Playgroud)
随着ruby 1.9.2的回归
<Enumerator:0x0000010086be50>
Run Code Online (Sandbox Code Playgroud)
红宝石1.8.7:
# 1
# 2
# 3
Run Code Online (Sandbox Code Playgroud)
分配变量......
x = [1,2,3].map do |x|
x + 1
end.inspect
puts x
Run Code Online (Sandbox Code Playgroud)
[2,3,4]
小胡子块按预期工作:
puts [1,2,3].map { |x| x + 1 }.inspect
Run Code Online (Sandbox Code Playgroud)
[2,3,4]
我正在使用一个包含大型实例数组的类.
每当我初始化这样的一类,例如i = Image.new,我从我的阵列中大量的垃圾输出(@r,@g,@b-每个〜300K值).
class Image
def initialize(width=640, height=480, brightness=64)
@width, @height, @brightness = width, height, brightness
self.load('usart.dat')
end
def load(file='usart.dat')
self.reset
f = IO.read(file, @height * @width * 2, 0)
# Parsing the datafile, saving data in @r, @g, @b, @gray etc
end
return self
end
# ... More methods
end
Run Code Online (Sandbox Code Playgroud)
问题是,我怎样才能使输出静音(所有结果都保存到文件中,从不在控制台中查看)或者使初始化程序不检查自身.我想返回self,因为我想要堆叠方法,例如image.load('file').binary.grayscale.save(:bin).