Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So what I wonder about is preaty simple - having in mind next architecture:

         -> computing unit "A"
gateway --> computing unit "B" same as A
         -> computing unit "C" same as A

We do not care to which unit to forward request so we should forward them one by one to A than to B than to C and than to A, etc.

I wonder in what language, using what framework it is possible to create such crossplatform TCP proxy/gateway (not ethernet card dependent) that would redirect incoming requests into internal nodes via simple rool, and would be capable to get as much as possible from ethernet cable load in/out capabilety - receive and send as much as possible?

I started to wonder after I read this nice 2003 article...

share|improve this question

closed as off-topic by MichaelT, Snowman, GlenH7, durron597, Dan Pichelman Oct 5 '15 at 21:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about what language, technology, or project one should take up next are off topic on Programmers, as they can only attract subjective opinions for answers. There are too many individual factors behind the question to create answers that will have lasting value. You may be able to get help in The Whiteboard, our chat room." – Community, Snowman, GlenH7, durron597, Dan Pichelman
If this question can be reworded to fit the rules in the help center, please edit the question.

Have you considered using a tried-and-true load balancer like HAProxy? This doesn't sound like a problem that requires reinventing the wheel. – Adam Maras Dec 19 '11 at 22:14
HAP is not supported for windows, I want to be capable to create scenarios harder than simple load balancing in future, when you write something on your own - you can rely on that a bit more... – myWallJSON Dec 19 '11 at 22:32
Have you considered throwing some networking hardware at the problem? – mattnz Dec 19 '11 at 23:20
@mattnz I agree, Cisco has some routers with load-balance capabilities, and they are fairly flexible in the policy configuration for balancing. – Fabio Ceconello Dec 19 '11 at 23:36
I'd also point out that the article you mentioned may be too simplistic. It's not like just dividing clock. memory & etc. by the number of clients. There's a lot more going on in the OS. Just consider this excerpt "that's 50 KHz ... per client". Well, even simple routines will easily eat up 50K clock cycles in a CISC processor - just that makes one refresh per second in each client not viable. And the high level of abstraction modern OSes provide (think about it, from bare metal to TCP there's a lot of abstraction) comes at a cost in the form of overhead. – Fabio Ceconello Dec 19 '11 at 23:43
up vote 2 down vote accepted

Short answer: Use ZMQ

Long answer: With the input given in your question, I assume the following and have the given the short answer

  • You just forward the requests to the computing machines
  • The computing machine does the rest of the work
  • You want a cross platform TCP/IP framework

But there are other things to consider such as

  1. The number of requests you would be receiving per second(1 GBPs is still big)
  2. Is your job over only with forwarding requests to the machines because computing machines most often return results to the machine which called it (similar to master-slave nodes)
  3. What would be the average size of your requests?
  4. What in case you start increasing your computing machines?
  5. Are you trying an architecture for distributed computing?
  6. Finally and most importantly, do you need a forwarding client or a message queue?

ZMQ addresses all of the above but in my opinion, you may go for RabbitMQ if you are good with centralized message queues

share|improve this answer
4) average size - 50% 10kb in and out, 50% infinit tcp socket interaction, just out 5) Yes - I try to create destributed services framework. – myWallJSON Dec 20 '11 at 16:31
So you would be having a lot of requests per second (somewhere near a few thousands). You can then pass your data in a opaque format to your computing machines. ZMQ is cross-platform and you can go through the documentation. But if you need a more robust service I prefer RabbitMQ because it has a centralized broker architecture. This can also be done in ZMQ but you have to a bit yourself. I still assume that you need a message broker service. – Ubermensch Dec 21 '11 at 4:14

By maximum number of client I guess you're also wanting high throughput, otherwise the number of clients would be limited by the number of ports. For the highest possible throughput/performance you'll want native code.

I would look at C++ with Boost asio. With asio you would still want to:

  1. Ensure you have efficient buffer management. Asio provides some support for this.
  2. Tune your socket receive/transmit buffer size.
  3. Ensure you have properly set socket options (e.g. you may want TCP_NODELAY).
  4. Profile your application under load to see that it's doing what you think it's doing.

Also keep in mind you won't realistically get more than 700-800Mbps on a 1GBps adaptor.

If performance is less of an issue there are many choices, node.js would be interesting.

share|improve this answer
Asio is grate, and I get lot out of it, but I look for even more performant solutions... – myWallJSON Dec 19 '11 at 23:10
@myWallJSON Added some points you can look into. I don't think there's much to be gained beyond what asio already does. I think there are maybe a few small areas where you could squeeze a tiny bit more performance but not much. – Guy Sirton Dec 20 '11 at 0:49

This is really a job for HAProxy. In fact, if I recall correctly he recently saturated a 10Gbs Ethernet card using haproxy on something like an old Celeron processor.

If you really want to rewrite the wheel, at least start with the HAProxy source code. Its open source.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.