Playing a Websocket Sample - Only One Aksky Actor?

In the Websocket chat example, presented with a playback framework, it seems to me that only one actor has ever been created / used; In addition, it uses “receive”, which, if I understood well, made it display 1: 1 between the actor and the stream, effectively making this chat server single-threaded?

Check out the code here: https://github.com/playframework/Play20/blob/master/samples/scala/websocket-chat/app/models/ChatRoom.scala

If this analysis is correct? If so, do you have pointers to how this server can be made very scalable?

+6
source share
2 answers

Http://www.playframework.org/documentation/2.0.1/AkkaCore has some default dispatcher configuration information for the websites that are used in this example.

Each state of a connection to a WebSocket is controlled by an agent-agent. A new actor is created for each WebSocket and is killed when the socket is closed.

This webpage also shows the default configuration:

websockets-dispatcher = { fork-join-executor { parallelism-factor = 1.0 parallelism-max = 24 } } 

By default, all dispatchers will start their membership set in the thread pool. Therefore, for each client creating a web layout, an actor will be created. How many threads are allocated depends on which executor service is used. It seems that fork-join-executor will create threads on demand before parallelism-max .

In addition, there are actors for handling actions and promises.

It seems that there are a lot of controls in Acca to fine-tune performance. See http://doc.akka.io/docs/akka/2.0.1/general/configuration.html . Creating a “highly scalable” server is likely to require a lot of benchmarking and some hardware.

+8
source

Although there will be an actor pool in the connections to the websites, but the ChatRoom actor is the only one (one actor instance) that does the actual processing of messages, controls connection / disconnection and acts as a router for sockets, which can be a bottleneck for this design. since messages are always processed sequentially for the actor. I doubt the sample is for scalability, but a simple demo for websites.

+5
source

Source: https://habr.com/ru/post/915450/


All Articles