Rui Sousa
Rui Sousa

Reputation: 3

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?

Upvotes: 0

Views: 687

Answers (3)

Reed Copsey
Reed Copsey

Reputation: 564433

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

Upvotes: 1

Sid
Sid

Reputation: 7631

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.

Upvotes: 1

Martin Beckett
Martin Beckett

Reputation: 96109

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

Take a look at either openMPI or MPICH

Upvotes: 3

Related Questions