This is a question which I have worked for several years, but now I still don't get a good solution.

My application has two part:

1. The first one is running in a server which is called "ROOT server". It will receive the realtime stock data from HKEx(Securities and futures exchange in Hong Kong), and broadcast them to 5 other children servers. It will append a timestamp to each data item when broadcasting.
2. The second ones are running in the "children" servers. They will receive the stock data from ROOT server, parse each of them, and get the important information. At last, they will send them in a new text format to the clients. The clients may be hundreds to thousands, they can register for some kind of stocks, and get the realtime information of them.

The performance is the most important thing. In the past several years, I tried all kinds of solutions I know to make it faster. The "faster" here means, the first one will receive and send the data to the children servers as fast as it can, and the children servers will receive and parse and send the data to the clients as fast as they can.

For now, when the data speed is 200K from HKEx and there are 5 children servers, the first one application will have 10ms latency for each data item in average. And the second one is not easy to test, it depends on the clients count.

What I'm using:

1. OpenSUSE 10
2. Sun Java 5.0
3. Mina 2.0

The server hardware:

1. 4-core CPU (I don't know the type)
2. 4G ram

I'm considering how to improve the performance.

1. Do I need to use a concurrent framework as [akka](http://akka.io)
2. try another language, e.g. Scala? C++?
3. use the [real-time java system](http://java.sun.com/javase/technologies/realtime/index.jsp)?
4. your advices...

Need your help!

---

Update: 

The applications have logged some important information for analysis, but I don't find any bottlenecks. The HKEx will provide more data in the next year, I don't think my application will be fast enough.

One of my customer have tested our application and another company's, but ours didn't have advantage in speed. I just want to find a way to make it faster.

**How is the first application running**

The first application will receive the stock data from HKEx and broadcast them to several other servers. The steps are:

1. It connects HKEx
2. logins
3. reads the data. The data is in binary format, each item has a head, which is 2 bytes of integer which means the length of body, then body, then next item.
4. put them into a hashmap in memory. Key is the sequence of the item, value is the byte array.
5. log the sequence of each received item into disk. Use log4j's buffer appender.
6. a daemon thread try to read the data from hashmap, and inserts them into postgresql in every 1 minute. (this is just used to backup the data)
7. when clients connect to this server, it accepts them and try to send all the data from hashmap from memory. I used thread pool in mina, the acceptor and senders are in different threads.

I think the logic is very simple. When there are 5 clients, I monitored the speed of transfer is only 1.5M/s at most. I used java to write a simplest socket program, and found it can be 10M/s. 

Actually, I've spent more than 1 year trying all kinds of solutions on this application, just to make it faster. That why I feel desperate. Do I need to try another language than Java?

---

**about 10ms latency**

When the application received a data from HKEx, I will record the timestamp for it. When the root server broadcast the data to the children servers, it will append the timestamp to the data.

when children server get the data, it will send a message to root server to get the current timestamp, then compare them. 

So, the 10ms latency contains:

1. root server got the data ---> the child server got the data
2. child server send a request for root server's timestamp ---> root server got it

But the 2nd one is very small that we can ignore it.