如何限制每个客户的球衣配额
我已经通过 jersey 框架构建了 Web 服务 API。 现在我想限制每个客户的配额。 例如: - 一个客户一天只能发出少于10000个请求。 - 一个客户端每秒只能发出少于 10 个请求。 等等。
我应该将这些信息存储在数据库的表中吗? 但如果我这样做,会花费很多时间来处理这些请求,因为我必须更新表。
我期待其他有效的方法来解决这些问题。 因为这是我第一次做这种工作,希望有人能在这些问题上给我一些建议。 谢谢~!
I've already built the web service API by jersey framework.
Now I want to limit the quotas for every client.
For example:
- one client can only make less than 10000 requests in one day.
- one client can only make less than 10 requests per second.
so on and so forth.
Should I store these information in the table of the database?
But if I do that, will it cost a lot time to handle these requests because I have to update the table.
I am looking forward to other efficient ways to solve these problem.
Because this is my first time to do this kind of job, hope somebody can give me some advise to in these problems.
Thanks~!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不了解如何定义客户,就很难回答这个问题。然而,一种方法是使用 ContainerRequestFilter
然后,在该级别,您可以定义客户端是什么,并记录该客户端对 Jersey 应用程序的所有访问。也许可以通过增加 DataStructure 中的值或数据库中的值来实现。然后让 cron 作业每 24 小时刷新一次该数据。
理想情况下,您希望将数据存储在内存数据结构中,因为数据是瞬态的,它不会增长到很大,并且无论如何都会在短时间内被删除。但是,如果您扩展到多台计算机或一台计算机上的多个实例,这将成为一个问题。
如果没有您提供更多信息,我无法提供更多信息
Without information about how you define a client its difficult to answer this question. However one method would be to filter all incoming requests using a ContainerRequestFilter
Then at that level you can define what a client is, and log all accesses by that client to your Jersey application. Perhaps by incrementing a value in a DataStructure or a value in a database. Then having a cron job flushes that data every 24 hours.
Ideally you would want to store the data in an in-memory data structure, since the data is transient, it won't grow to a large size and will be deleted in a short period of time anyway. However this will become an issue if you ever scale up to multiple machines, or multiple instances on a single machine.
Without more information from you I can't really give any more information