Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Cómo verificar cuál es el límite de aceleración para su acceso a un punto final con JS

[![ingrese la descripción de la imagen aquí][1]][1]Necesito implementar un código para verificar cuál es mi límite de aceleración en un punto final (sé que es x veces por minuto). Solo he podido encontrar un ejemplo de esto en python, que nunca he usado. Parece que mis opciones son ejecutar un script para enviar la solicitud repetidamente hasta que me limite o, si es posible, consultar la API para ver cuál es el límite.

¿Alguien tiene una buena idea sobre cómo hacer esto?

Gracias.

Nota: El espacio en blanco son solo datos de las llamadas a la API. [1]: https://i.stack.imgur.com/gAFQQ.png

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto inicia concurency del número de trabajadores (estoy usando trabajadores como un término suelto aquí; no me @). Cada uno hace tantas solicitudes como sea posible hasta que una de las solicitudes tiene un límite de velocidad o se queda sin tiempo. Les informa cuántas de las solicitudes se completaron con éxito dentro de la ventana de tiempo dada.

Si conoce la ventana de límite de tasa (1 minuto según su pregunta), encontrará el límite de tasa. Si necesita descubrir la ventana, querría agotar intencionalmente el límite, luego ralentizar las solicitudes y medir el tiempo hasta que comenzaron a pasar nuevamente. El código proporcionado no hace esto.

 // call apiCall() a bunch of times, stopping when a apiCall() resolves // false or when "until" time is reached, whichever comes first. For example // if your limit is 50 req/min (and you give "until" enough time to // actuially complete 50+ requests) this will call apiCall() 50 times. Each // call should return a promise resolving to TRUE, so it will be counted as // a success. On the 51st call you will presumably hit the limit, the API // will return an error, apiCall() will detect that, and resolve to false. // This will cause the worker to stop making requests and return 50. async function workerThread(apiCall, until) { let successfullRequests = 0; while(true) { const success = await apiCall(); // only count it if the request was successfull // AND finished within the timeframe if(success && Date.now() < until) { successfullRequests++; } else { break; } } return successfullRequests; } // this just runs a bunch of workerThreads in parallell, since by doing a // single request at a time, you might not be able to hit the limit // depending on how slow the API is to return. It returns the sum of each // workerThread(), AKA the total number of apiCall()s that resolved to TRUE // across all threads. async function testLimit(apiCall, concurency, time) { const endTime = Date.now() + time; // launch "concurency" number of requests const workers = []; while(workers.length < concurency) { workers.push(workerThread(apiCall, endTime)); } // sum the number of requests that succeded from each worker. // this implicitly waits for them to finish. let total = 0; for(const worker of workers) { total += await worker; } return total; } // put in your own code to make a trial API call. // return true for success or false if you were throttled. async function yourAPICall() { try { // this is a really sloppy example API // the limit is ROUGHLY 5/min, but because of the sloppy server-side // implimentation you might get 4-6. const resp = await fetch("https://9072997.com/demos/rate-limit/"); return resp.ok; } catch { return false; } } // this is a demo of how to use the function (async function() { // run 2 requests at a time for 5 seconds const limit = await testLimit(yourAPICall, 2, 5*1000); console.log("limit is " + limit + " requests in 5 seconds"); })();

Tenga en cuenta que este método mide la cuota disponible para sí mismo . Si otros clientes o solicitudes anteriores ya han agotado la cuota, afectará el resultado.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!