0

Now I am building an application to send big data from client to server via UDP. I have some questions are:

  1. Should I use one thread to send data or multi-threads to send data?
  2. If I should use multi-threads to send data, I will use one socket for all threads or one socket per one thread?

Thanks,

1
  • Yes. You should definitely use one thread or mulitple threads. Which depends on what you are trying to do. Commented Dec 13, 2018 at 4:21

1 Answer 1

1

Should I use one thread to send data or multi-threads to send data?

Either way can work, so it's mostly a matter of personal preference. If it was me, I would use a single thread rather than multiple threads, because multiple threads are a lot harder to implement correctly, and in this case they won't buy you any additional performance, since your throughput bottleneck is almost certainly going to be either your hard disk or your network card, not the speed of your CPU core(s).

If I should use multi-threads to send data, I will use one socket for all threads or one socket per one thread?

Again, either way will work (for UDP), but if it was me, I would use one socket per thread, only because then you don't have to worry so much about race conditions during process-setup and process-shutdown (i.e. each thread simply creates and destroys its own separate/private socket, so there's no worrying about who does what to the socket when)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.