简体   繁体   中英

C++ Multi-threading with multiple machines

Well my problem is the following. I have a piece of code that runs on several virtual machines, and each virtual machine has N interfaces(a thread per each). The problem itself is receiving a message on one interface and redirect it through another interface in the fastest possible manner.

What I'm doing is, when I receive a message on one interface(Unicast), calculate which interface I want to redirect it through, save all the information about the message(Datagram, and all the extra info I want) with a function I made. Then on the next iteration, the program checks if there are new messages to redirect and if it is the correct interface reading it. And so on... But this makes the program exchange information very slowly...

Is there any mechanism that can speed things up?

Somebody has already invented this particular wheel - it's called MPI

Take a look at either openMPI or MPICH

Why don't you use queuing? As the messages come in, put them on a queue and notify each processing module to pick them up from the queue. For example:

  • MSG comes in
  • Module 1 puts it on queue
  • Module 2,3 get notified
  • Module 2 picks it up from queue and saved it in the database
  • In parallel, Module 3 picks it up from queue and processes it

The key is "in parallel". Since these modules are different threads, while Module 2 is saving to the db, Module 3 can massage your message.

You could use JMS or MQ or make your own queue.

It sounds like you're trying to do parallel computing across multiple "machines" (even if virtual). You may want to look at existing protocols, such as MPI - Message Passing Interface to handle this domain, as they have quite a few features that help in this type of scenario

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM