开发者

Efficient TCP Server and Data conversion in Java

Background

In my java application, I have reasonably large amounts of data sitting in ConcurrentHashMap.

Now, I need to give this data to a consumer client in XML format when the client connects to my application via a TCP port.

So in a nutshell - I have a TCP Server that a client connects to. As soon as the client connects, I have to read all the data in the Map and spit it out in XML format (custom) on the TCP port. The data in the Map keeps getting updated automatically from somewhere else using worker threads etc, so I have to keep sending the fresh data over and over to the client on this tcp port.

I want to implement a solution that is memory and cpu efficient - Mainly I would prefer not to generate too many immutable objects in the heap. .

NOTE:In future I might have to support multiple output f开发者_JAVA百科ormats (like comma separated or Json or HL7 etc). To keep it simple lets say there's different TCP port the client can connect for a specific format.

Question

With that said - I've been looking around for the best solution for my TCP Server implementation and data conversion process from ConcurrentHashMap to XML.

For TCP Server, people talk about

  • NETTY

  • Kryonet

  • Apache MINA

My client will be some third party, so i think kryonet is out, since client wont do the "register" business needed by Kryonet. So out of MINA and NETTY, which one is scalable and easier to understand? Any other suggestion?

FOR data conversion from ConcurrentHashMap to XML, I was thinking of using XSTREAM Any other suggestion?

Thanks


If you have 100s or 1000s of connections you should start to consider scalability. However if you have small number of connections, using plain Sockets may be all you need.

If only a portion of the data is changing, you better off sending only the data which has changed, or at least only regenerating the XML which has changed.


How fast does it need to be? It seems like you should be able to create something that returns in less than 10ms (plus RTT) just using tomcat and a standard framework like spring-mvc. Use JAXB to convert objects to XML. If you want to support additional output formats like json it's trivial (use Jackson library for that, api is similar to JAXB).

I had a co-worker that tried the socket server approach and in the end we used tomcat because it was almost as fast and the QPS was more stable/predictable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜