luminus-framework / luminus-template

a template project for the Luminus framework
http://www.luminusweb.net/
MIT License
645 stars 147 forks source link

Support for Async Ring Handlers #571

Closed grmble closed 1 year ago

grmble commented 1 year ago

I have one project where I need to efficiently serve lots of data that I aquire as a CompletableFuture, I need to deploy the application as a War File on a Tomcat I don't control, and the incoming data has severe lag spikes so I really hate to use 1 thread for every connection.

I went down the rabbit hole of using Async Ring Handlers, and while I see the problems (all or nothing approach, no timeout mechanism) this opens up the whole ring ecosystem for my use case.

I don't plan to use this in every project, but having the option to spin up a quick prototype with Luminus would be nice.

Status so far is

This probably also needs a feature switch. I would put the 1-and-3 arity fixes for the general purpose middleware in the main template, the helpers for async operation would go into the +async feature.

yogthos commented 1 year ago

That sounds reasonable to me. If you'd be up for doing a pr for the template, I can definitely help with getting it out.

grmble commented 1 year ago

Right now I am playing with war file generation - it works, but only sync. For async operation you need servlet 3.0+ with opt-in in the generated web.xml, and then tomcat complains with mysterious error messages.

"IllegalStateException: calling asyncPostProcess() is not valid for a request with async state" and

"checkRecycled encountered a non-recycled event and recycled it forcefully"

I will make a PR when it is in decent shape.

Edit: the strange error messages were caused another missing 3 argument handler, it just took me a while to find it. The trick was getting a useful error message ...

yogthos commented 1 year ago

Sounds like a plan, just ping me when you want a review for the PR and we can get it in.