Scala way to use one actor in one socket connection

I am wondering how to avoid one pr socket socket. stream in Scala. I thought a lot about this, but I always get code that listens for incoming data for each client connection.

The problem is that I want to develop an application that should handle several thousand connections at the same time. However, of course, I do not want to create a thread for each connection due to the lack of scalability and context switching.

What would be the β€œright” way to do this. In my world, it should be possible to have one actor for each connection without having to block one thread for each actor.

+5
source share
2 answers

I have an application that mixes actors with non-blocking sockets (i.e. NIO). The way I did this is to have a dedicated I / O stream that sends messages to the actors (much like it delegates the work to a thread pool in a Java system) using a reactor template.

Obviously, using old blocking sockets, you are limited to one thread per connection. And the actor can handle this, but, of course, this limits the number of connections that can be processed simultaneously.

- , ( ), - - . , NIO .

+4
+6

All Articles