Are multiple boost::asio tcp channels faster than a single one? - c++

In linux, axel is generally faster than wget. The reason is that axel opens multiple channels (connections) to the source and downloads the pieces of a file simultaneously.
So, the short version of my question is: Would doing the same with boost::asio make the connection transfer data faster?
By looking at these simple examples of a client and a server, I could make a single connection initiate multiple client instances, and connect to the same server with multiple sessions. In the communication protocol, I can make the client and server ready for such connections in such a way, where data is split among all the connection channels.
Could someone please explain to me why this should or shouldn't work out based on the scenarios I drew?
Please ask for more details if you need it.

Related

How to create multiple connection to one specific address in C++ GRPC client

I wrote a c++ grpc client, and wanted to create multiple connection by create multiple channel, just like the hello world example.
But only one connection for the specific address was created. So how to create multiple connection to the server?
Honestly, I don't see significant reasons for that (at least for basic use cases). You don't need to create multiple connections to have some kind of connection pooling (as you might want to do while connecting to RDBMS like PostgreSQL). The bandwidth of physical transport (TCP connection) will be fully utilized by the single network connection.

ZMQ server/client pattern

It is a general question about patterns used in zmq. I'm trying to achieve the following.
Client can connect to one server
Multiple clients connect to the same server
Server receives connections from multiple clients
Server processes multiple messages in parallel
Think of any webserver, just without all the HTTP stuff around it. The question is the Paranoid Pirate Pattern a good candidate for such client/server? I guess it is a good idea to connect the backed socket to the workers using inproc since the queue and workers will be part of the same process, right? In case there is dozens to hundreds workers used, how should I work with the zmq::context_t? should I initiate it with high number of io_threads or use a zmq::context_t per worker?
EDIT001: Interestingly, zmq example of Paranoid Pattern does not work out of the box.

TCP Server - Multi User File Upload

I'm struggling with trying to figure out how to implement a TCP server in python. I currently have a TCP server that can connect to one client at a time. The Client can successfully communicate with the server, and upload a file using a single socket. Currently, it is single threaded and when one Client connects it blocks the other clients from connecting until it is done.
I'm struggling with the design portion on making this multi-client friendly. If I'm uploading files concurrently should there be multiple sockets? If I go with one socket, how do I differentiate data from different clients?
Can anyone give some advice on this?

C++ & Boost: I'm trying to find an example TCP program with a server that accepts connections from multiple clients

A chat program would be a good enough example.
Just need a server that can accept multiple connections from the clients, and the server needs to be able to send messages to individual clients.
I plan to turn this into a distributed computing program to work with multiple Neural Networks.
Asio is the Boost library that handles networking. There's a chat server example listed here.
I cannot give you an example progam. But to write a server things that you have to do:
1. server will listen at a port for connection
2. thread pool which will accept the connection and serve request
3. write the server code in thread safe manner
You have to use socket programming A good link for that http://beej.us/guide/bgnet/
you can use win32 api in windows and posix for linux

Linux socket programming testing

I am new to socket programming and I have written a code for the server using the epoll. Basically it would wait to accept for any client connection and it would send data to the clients if the data is available from other sources.
I need to test on how is the performance of the server when there are multiple requests for the connection and when the server is sending data to multiple clients. The question I have is how could I simulate a concurrent requests of the connection from a number of clients for the server? Do I create multiple threads to request or multiple processes or some other ways to test it?
Thanks.
I usually create a client program simulating one session with the server, find as many linux boxes nearby and spin up a thousand of them on each machine from a command line like:
for i in {0..1000} ; ./myprogram serverip & done
In some cases the protocol is text based and the interaction or test is simple, so I don't have to write myprogram but just use netcat, as in running nc serverip < input >/dev/null
If all you need is to test streaming data to your client, I'd start with netcat and work my way from there.
This approach is ok for my needs, I usually don't need to test more concurrency than a handful of thousand clients. If you need more scalability, you'll likely have to write the client simulator using io multiplexing (epoll) as well, having each instance simulate as much interactions as you can - and you'll have to do more controlled tests to find limits of your client .
Don't mix performance testing with functional testing though. While you might get awsome performance in a test environment, a live environment can be very different. e.g. clients will misbehave, they will disconnect at the most inapproriate of times. They might send you malicious data. They might be slow, leading to buildup of internal queues on the server or leving you with thousands of seemingly idle connections (killall -STOP nc while in the middle of sending data to test clients might show you interresting things)
You can do it using two threads one to send request and other to receive response.
To simulate multiple clients you can create multiple sub-interface using ifconfig command in a script or using ioctl in your c program.
For sending data from client you can create array of multiple sockets and bind them to different sub interface IPs and loop through them for sending data and use select or poll for receiving data from server.