【发布时间】:2017-06-28 12:43:00
【问题描述】:
我正在开发一个服务于大文件的 HTTP 服务。我注意到并行下载是不可能的。该过程一次只提供一个文件,所有其他下载都在等待之前的下载完成。如何同时流式传输多个文件?
require "http/server"
server = HTTP::Server.new(3000) do |context|
context.response.content_type = "application/data"
f = File.open "bigfile.bin", "r"
IO.copy f, context.response.output
end
puts "Listening on http://127.0.0.1:3000"
server.listen
一次请求一个文件:
$ ab -n 10 -c 1 127.0.0.1:3000/
[...]
Percentage of the requests served within a certain time (ms)
50% 9
66% 9
75% 9
80% 9
90% 9
95% 9
98% 9
99% 9
100% 9 (longest request)
一次请求 10 个文件:
$ ab -n 10 -c 10 127.0.0.1:3000/
[...]
Percentage of the requests served within a certain time (ms)
50% 52
66% 57
75% 64
80% 69
90% 73
95% 73
98% 73
99% 73
100% 73 (longest request)
【问题讨论】:
标签: crystal-lang