Java application with clustered event. Should I be using Websockets or Poll?

I am creating a monitor application that monitors user actions. There are four elements on my system :

EventCatcher

: EventCatcher

responsible for detecting all events occurring in the subsystem and pushing the data to EventHandler

. Based on observations, on average 10 events per second have to be clicked on EventHandler

. Some events: UserLogin, UserLogout.

EventHandler

: EventHandler

is a singleton class that handles all incoming events from EventCatcher

. It also keeps track of all registered users on the system. This way, whenever the EventHandler

UserLogin event is received, the object User

is retrieved from the event and stored in HashMap

. When a UserLogout event is received, this object User

will be removed from HashMap

. This class also supports Set

all active Websocket sessions, because every time an event happened, I would like to tell all open sessions that a particular event happened.

Websocket Endpoint

: This is a simple Java class annotated with @ServerEndpoint

.

Clients

A: The system that I will be building is for internal (corporate) use only. In production, at most, there will be only about 5 to 10 customers. All clients will receive the same information every time an event occurs.

So now I'm trying to convince my supervisor that Websockets is the way to go, but my supervisor thinks it's unnecessary because a simple polling solution would do the trick.

Its points:

  • We don't need the updated millisecond information. We can poll every second.
  • If I were to maintain a list of open WebSocket sessions as it works in a clustered environment (we are using load balancing)
  • If I plan on sending information to the client every time an event (UserLogin, UserLogout) has occurred, I should be able to just send small updates to all WebSocket sessions, i.e. I cannot send the entire JSON dump from everything. So this means that for each WebSocket instance, I will have to maintain a different set of users and maintain it correctly in order to mirror the set contained in EventHandler

    .

What my supervisor suggests is that I lose the WebSocket and just convert it to a simple servlet and check the clients each time to get the whole JSON dump.

In this case, should I stick with WebSockets? Or should I just poll?

The main advantage, in my opinion, is that with Websockets you will have a persistent connection from client to server. HTTP is not designed for live data.

Additionally, polling requires an HTTP request to be sent every time, and each request comes with HTTP headers. If the HTTP request header contains 800 bytes, then this 48kb is sent per minute per client. With WebSocket, this is not a problem.

But then again, we really won't have many active clients. We don't care about third parties sniffing our requests because this system is for company use only - internal use! And I believe my manager wants something simple and reliable.

I'm fine with any way. I just want to make sure I'm using the right tool for the job.

Additional question: If WebSockets is the way to go, is there a reason why I should consider polling?

+3


source to share


1 answer


The whole purpose of WebSocket is to efficiently maintain continuous connections between client and server.

I don't understand how you are implementing your application. If this is a web application running in a Servlet environment, using WebSocket support on the web server, keep in mind that you need to use the latest Servlet container. For example, with Tomcat, you must use either version 8 or the latest updates to version 7.

And, of course, the web browser must have WebSocket support.

Remember that WebSocket is still a new technology that has changed and evolved in both specifications and implementations.



Atmosphere

You might want to consider the Atmosphere schema . Atmosphere supports multiple Push methods including WebSocket and Comet.

The Vaadin web-app framework uses Atmosphere to automatically support Push in your application. By default, WebSocket will automatically try to execute from the beginning. If no WebSocket is available, Vaadin + Atmosphere automatically falls back to other methods, including polling.

0


source







All Articles