简体   繁体   English

API 速率限制 Python - 设计

[英]API Rate limiting Python - Design

I am currently trying to create a throttler decorator to limit my api calls accross all my app.我目前正在尝试创建一个节流器装饰器来限制我的 api 调用跨越我的所有应用程序。

My idea is to use threading.semaphore and/or threading.timer to track and block the request which are above the rate limit.我的想法是使用threading.semaphore和/或threading.timer来跟踪和阻止高于速率限制的请求。

I already have something working, however my concern is that with this solution i will start a thread per request.我已经有一些工作了,但是我担心的是,通过这个解决方案,我将根据请求启动一个线程。 So lets say i'm making 5000 calls per minute, could this cause any issue / is bad practice?所以假设我每分钟拨打 5000 个电话,这会导致任何问题/是不好的做法吗?

Good practice is to use something that already exists in the framework you are using.好的做法是使用您正在使用的框架中已经存在的东西。 There are ready-made solutions for Django and DRF, for example.例如,Django 和 DRF 有现成的解决方案。 Something similar is bound to exist for the framework you are using.您正在使用的框架必然存在类似的东西。 If you are developing a web api, that is.如果您正在开发 web api,那就是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM