简体   繁体   English

当 API 关闭时请求优先级

[英]Request prioritization when an API is down

Imagine an API with an endpoint called /valuableData.想象一个带有名为 /valueableData 的端点的 API。 The server clearly states that the limits for the API are 500 requests/s in total and 20 requests/s per person.服务器明确指出 API 的限制是总共 500 个请求/秒和每人 20 个请求/秒。 This server does not check your IP so I could make 500 request/s with 500 good working proxies without the API going offline.该服务器不会检查您的 IP,因此我可以使用 500 个正常工作的代理发出 500 个请求/秒,而 API 不会脱机。 Now imagine that person A sends 1000 requests/s and person B sends 20 requests/s which causes the 500 limit to be hit and the API goes offline.现在假设 A 发送 1000 个请求/秒,B 发送 20 个请求/秒,这会导致达到 500 个限制并且 API 离线。 As soon as the API comes back online, how many valid answers does person A get back per second and how many person B? API 重新上线后,A 每秒返回多少个有效答案,B 返回多少个有效答案? How does the server/API handle this?服务器/API 如何处理这个问题? Does person A get back 480 valid answers per second and person B 20?人 A 每秒能得到 480 个有效答案,而人 B 每秒能得到 20 个有效答案吗? Or does person A get all the max of 500 answers/s?或者 A 是否能得到最多 500 个答案/秒?

This depends on the protocol.这取决于协议。

HTTP which normally is used for REST is in itself stateless and client-initiated and therefore falls short of the requirements.通常用于 REST 的 HTTP 本身是无状态的和客户端启动的,因此不符合要求。

Your scenario would require a protocol which:您的方案需要一个协议,该协议:

  1. Knows who the clients are/were知道客户是谁/曾经
  2. Can push responses after coming online again without client involvement再次上线后可以推送回复,无需客户参与
  3. Can prioritize responses to client requests可以优先响应客户请求

I imagine such a protocol exists or could be implemented using WebSocket and storing state in a database.我想这样的协议存在或可以使用WebSocket实现并将状态存储在数据库中。

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

相关问题 根据先前请求的结果降低API请求的速度 - Slow down an API request that depends on the result of a prior request 如何在不减慢服务器速度的情况下向 api 发送数千个并发请求? - how to send thousands concurrent request to api without slowing down server? zendesk服务器关闭时连接到Zendesk API - Connecting to Zendesk API when zendesk server is down 发出 API 请求时出现 JSONDecodeError - JSONDecodeError when making an API request cURL 请求(使用 Stripe API)减慢页面加载时间 - 发出请求的最佳方式? - cURL request (with Stripe API) slowing down page load times - optimal way to make the request? 在api上jquery ajax请求时出现CORS错误 - CORS error when jquery ajax request on api 构建apk Flutter时请求不进入Api - Request not goin to Api when build apk Flutter 向 API 发出请求时出现 ConnectionError url - ConnectionError when making request to API url 当请求没有匹配的 API 时,为什么我的 controller 调用不同的 API? - Why is my controller calling different API when there is no match API for the request? API 按下按钮时请求未显示在模拟器上 - API Request not showing on simulator when button pressed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM