How do you know how many requests are pending service?

Sometimes my application needs to do some blocking operations (simple math). As a result, other requests will be blocked until the calculation is completed. Is there a way to count the number of pending requests?

EDIT: adding more details. The blocking operations are very small (maybe just adding numbers or addition / multiplication loops Eg: var foo = 3 + y;

), but the point is, anything that is not IO is probably blocking.When there are not many users, it might not be noticeable because the calculation is very fast. But as more users access the site, the experience gets much worse.

EDIT: If this feature is not present, I think it would be helpful. Because then we know when to launch a new server (like an AWS server or another cloud provider). Running at full capacity is fine if we can satisfy all the requests, but not ok if the requests start to pile up. XD

+3


source to share


1 answer


You cannot count the number of pending requests, because they are really just queued by instructions, and after the time expires your "count" code will run, the queue will be empty again. JavaScript is single threaded, so if you are not using async you may not even be able to swap in time.



If you want to manage this, implement your own queuing mechanism and manage the work yourself. The package async

can provide this for you.

0


source







All Articles