We have a somewhat unique case where we need to interact with an external API, which requires us to take a long survey of their endpoint for what they call real-time events.
The fact is that at any given time up to 80,000 people / devices can be involved, affecting this endpoint, listening to events, 1 connection per device / person.
When a client makes a request to our Spring service for a long poll for events, our service, in turn, calls an asynchronous call to an external API for a long poll for events. The external API defined a minimum long polling timeout, which can be set to 180 seconds.
So, we have a situation where the thread pool with the queue will not work, because if we have a thread pool with something like (5 minutes, 10 max, 10 queues), then 10 threads that will work can be spotlighted and 10 in the queue will not get a chance until one of the current 10 is completed.
We need a feed or failure (we will put load balancers, etc.), but we do not want to leave the client hanging without an actual survey.
We studied the use of DeferredResult for this and returned it from the controller.
Something to the tune
@RequestMapping(value = "test/deferredResult", method = RequestMethod.GET) DeferredResult<ResponseEntity> testDeferredResult() { final DeferredResult<ResponseEntity> deferredResult = new DeferredResult<ResponseEntity>(); CompletableFuture.supplyAsync(() -> testService.test()).whenCompleteAsync((result, throwable) -> deferredResult.setResult(result)); return deferredResult; }
I am wondering if I am on the right track, and also have to provide the executor and which executor (and configuration) the CompletableFuture.supplyAsync()
method in order to best accomplish our task.
I read various articles, posts, etc., and I want to find out if anyone has knowledge that can help in our specific situation.