用rails进行带宽管理? [英] bandwidth management with rails?

查看:70
本文介绍了用rails进行带宽管理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道一种可以以某种不依赖于Web服务器的方式来管理Rails应用程序中的带宽的方法.例如,每个帐户都有带宽限制.进出境交通量是否从每月津贴中扣除?

I was wondering if anyone knew of a way that you could manage bandwidth within a rails application in some way that isn't dependent on the web server. For example each account has a bandwidth limit. In and out bound traffic subtracts from the monthly allowance?

推荐答案

一种选择是在application.rb中添加一个after_filter(这样它就适用于所有操作)并执行以下操作:

One option would be to add an after_filter in application.rb (so that it applies to all actions) and do the following:

def store_bandwidth_usage
   response_size = response.body.size
   # Assuming the User model has a bandwidth_usage attribute
   @current_user.increment!(:bandwidth_usage, response_size) 
end

当然,您将需要一个before_filter来检查用户是否没有超出分配的带宽,否则应拒绝他们的访问.

Of course then you would need a before_filter which checked that a user had not gone over their allocated bandwidth otherwise they should be denied access.

请记住,只有到达Rails服务器的请求才会计入此费用,前端服务器填充的任何请求(例如图像)都将不包括在内.

Keep in mind that this will only be counted for requests that hit the rails server, any requests that are filled by an front-end server (e.g. images) will not be included.

这篇关于用rails进行带宽管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆