【发布时间】:2015-01-13 03:54:15
【问题描述】:
我想用缓存或二进制响应
加快查询响应速度渲染 5k ~ 100k 条记录的 json 响应需要超过 30 秒 ~ 500 秒。
如何让它更快?
因为渲染时响应时间仍然很慢
是否可以进行二元响应(跳过渲染视图)?
WeatherLog Load (335.5ms) SELECT "weather_logs".* FROM "weather_logs" ORDER BY "weather_logs"."datetime" ASC LIMIT 90000
Write page /Users/public/index.json (35.2ms)
Completed 200 OK in 40488ms (Views: 32459.3ms | ActiveRecord: 336.8ms)
控制器
caches_page :index
respond_to :json
def index
begin
@weather_logs = WeatherLog.result(q)
respond_to do |format|
render json: @weather_logs
return
end
rescue Exception => e
respond_to do |format|
format.json { render json: {status: "Invalid Request #{e.backtrace.first(3)}"} }
end
end
end
数据流:第 4 步是渲染的瓶颈
简而言之
我只需在短时间内将响应发送给客户,
不管是什么格式。
即使是二进制格式也可以。
请给我一些方向或想法来提高性能
【问题讨论】:
-
流式响应是否适合您?见stackoverflow.com/a/24292549/2463468
-
生成的文件有多大(或单个条目有多大)?
-
@mdrozdziel 大约几十万到几百万
-
你不会把缓存结果和缓存响应混为一谈吗?
-
“几十万到百万”是什么单位?
标签: ruby-on-rails ruby-on-rails-4 jbuilder