Answer the question
In order to leave comments, you need to log in
How to properly organize work with sockets?
Hello! Newbie in java, maybe a lame question: I
have a java application (daemon, java 8) that needs to accept requests from other applications and give them responses. Decided to organize it on sockets.
Max. number of simultaneous requests 1000 (this is with a margin, in reality it will be about 300)
Request execution time ~ 0.2sec
Request data size ~ 100 bytes
Response size ~ 4Kb I
thought to do it in a simple way - using ServerSocket + ThreadPool, but when I started to delve into the topic , I saw that this is no longer cool, that you need to use NIO, Netty. For me, this is all new, I have never worked with sockets before.
Tell me how to do it right?
Plus, now the application is pure Java, but in the future I will wrap it in Spring. Maybe there is already something ready and it makes sense to work with sockets using Spring right away?
Thanks in advance!
UPDATE
This is not a web application, it's just a daemon that is not accessible from the outside. Its clients are php (both daemons and php-fpm processes) and a few other java/c++ applications running on the same machine (yes, we have a zoo here ;)
Answer the question
In order to leave comments, you need to log in
In general, I tested ServerSocket with my parameters (sent 100 bytes of text, output it to the console, gave 4Kb). On a working computer, it turned out that this option is able to process ~ 70 thousand requests per second. Considering that the server is much more powerful than the working computer, this result is more than satisfactory.
It will be correct as it is more convenient for you personally.
On my own, I can recommend a mine , it has a very cool Codec Filter for the convenience of working to get rid of the routine with bytes.
ServerSocket + ThreadPool - the classic connection handling model. Try Netty. It is very easy to make friends with the same Spring. Netty uses Java NIO, but you don't have to deal with pipes and buffers by hand. Java NIO uses a non-blocking (asynchronous) connection and message processing model to take your application to the next level.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question