Async implementation feedback
See original GitHub issueWe just released async support in Javalin 1.6.0!
However, I have a feeling that the current implementation isn’t perfect. Please use this thread to suggest improvements, or just to complain (then we’ll think up improvements).
The current (v1.6.0) implementation:
// usage:
app.get("/") { ctx -> ctx.result(string) } // blocking
app.get("/") { ctx -> ctx.result(completableFuture) } // async
// what happens behind the scenes:
tryBeforeAndEndpointHandlers()
val future = ctx.resultFuture()
if (future == null) {
tryErrorHandlers()
tryAfterHandlers()
writeResult(ctx, res)
} else {
req.startAsync().let { asyncContext ->
future.exceptionally { throwable ->
if (throwable is Exception) {
exceptionMapper.handle(throwable, ctx)
}
null
}.thenAccept {
when (it) {
is InputStream -> ctx.result(it)
is String -> ctx.result(it)
}
tryErrorHandlers()
tryAfterHandlers()
writeResult(ctx, asyncContext.response as HttpServletResponse)
asyncContext.complete()
}
}
}
Users who don’t care about async are not affected by the functionality in any way.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
An overview of asynchronous design feedback and its benefits
When someone approaches you and asks about a particular design, it means they are expecting instant response from you. This is called synchronous...
Read more >Feedback on async task examples and another possible ...
In this post I discuss some feedback on my previous posts about running async tasks on startup, including why database migrations were a ......
Read more >c# - How to provide a feedback to UI in a async method?
I have been developing a windows forms project where I have a 10 tasks to do, and I would like to do this...
Read more >Async Reviews 2022: Details, Pricing, & Features
It is easy to use and get along, also quick responsive. It was a smooth transition from other market tools. We are used...
Read more >The definitive guide to effective asynchronous ...
Async cheat sheet · 1. Process documentation · 2. Brainstorming · 3. Gathering feedback · 4. Status updates / weekly standup · 5....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I put together a sample async benchmark application based on my PR. The application can be found here: https://github.com/joatmon/spark-async-benchmark
I’ve included some sample scripts that demonstrate that, under heavy load, using async request processing for long requests improves the throughput of short synchronous requests by 750x.
When the short queries are competing for jetty threads with the long queries, the application is able to process 250 short requests in ten seconds. With the long queries handled by the async thread pool, the applications processes 188,454 short requests in ten seconds.
I got some great input from
/u/0x256
on/r/java
, I’m posting it here with his permission. In short, the current implementation is good for long running tasks with short responses (the problem we set out to solve), but there are some things we need to fix if we want Javalin to be truly async. We probably don’t want that, but the info he provided is great nonetheless: