I'm trying to understand reactive programming and how the event loop works. As long as I can understand when a new HTTP request is sent to the app, this request splits into events. And every event is handled by this event loop and for every event a callback is registered. On complete of this event, the result is returned to the request. But how many threads handles this request and how many threads are in this event loop.
CodePudding user response:
By default spring web flux uses reactor-netty as underlying Http Client library which itself is a reactive implementation of famous Netty client Event Loop Implementation. To learn more on how this works, you can refer to details here https://livebook.manning.com/book/netty-in-action/chapter-7/.
You can think like all requests are handled by limited threads usually 2 or 4 times the actual processor threads and each http client request is wrapped in a object and each event loop thread can pick up the object from Java heap and do some work and add the object back to memory.
Once response is received on port, event loop again picks up object from memory(Connection pool) and deserializes the response data from ByteBuffers to Object using Jackson.
Event loop is implemented in every os accordingly like epoll for linux, kqueue for macOS and Java NIO as default implementation to be OS agnostic.