on 2023 Nov 11 1:16 PM
Sorry about this stupid question, but I just wanted to get confirmation that my understanding is correct..
When providing a cap based service that is built with node.js, is there only one thread available to handle this request? I.e. If I have a long running service handler this blocks/queues any other caller of this service until it is completed.
And thus if I want multiple requests of that cap service, I need to spawn a second instance of the app?
Was making a test with a forced loop in the on-handler of am action and while this was running, triggered a second call of this action. It shows that this is only processing the second request if the first one left the loop. If I add a second instance of the app, it does immediately process a second request.
And would a similar cap service built with the java Version support multiple threads per one instance? And of so how many and how is this controlled?
Request clarification before answering.
This is a general question about differences between Node.js and Java. This is not specific to CAP. CAP just embraces the patterns of the underlying runtime.
Node.js uses the Event Loop concept, which basically processes everything in a single worker thread. This works well, for I/O bound scenarios. For CPU bound scenarios this can cause issues (your endless loop is highly CPU bound ;)). Technically it is possible to start multiple such worker threads in a single Node.js process, but I think the more common approach in Node.js is a scale out to multiple processes.
Java is multithreaded and has a thread model, where a new thread is spawned for each incoming request. In Spring Boot and Tomcat the upper bound of request threads can be configured (https://www.baeldung.com/java-web-thread-pool-config#1-embedded-tomcat). With JDK 21 and virtual threads Java will be able to go for a model that takes up some of the advantages of the event loop approach.
Here is some further reading on these topics:
- https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick
- https://snyk.io/blog/node-js-multithreading-worker-threads-pros-cons/
- https://www.infoworld.com/article/3678148/intro-to-virtual-threads-a-new-approach-to-java-concurrenc...
- https://www.baeldung.com/java-virtual-thread-vs-thread
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
21 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.