• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 928
  • Last Modified:

msg.h vs mqueue.h


What's the better api to use? (<-- a loaded question!)

Is there a difference between using mqueue or using msg calls? I need to write an application on AIX where one process is asked to do some work and then a second one would receive a message from the first to try and pre-empt what the first process will ask for next...

So basically, process one is asked by the user to get info on a client from a client database... The information is retrieved and sent to the user. At the same time, this process will send a message to another process to ask it to get more in-depth information about the same client and fill up a temporary database with all this information. When the user then asks the first process to get the in-depth information, the data will already be available and packaged accordingly.

So which messaging scheme seems better adapted to my specific problem?

-- Bubba
0
bganoush
Asked:
bganoush
  • 3
  • 2
1 Solution
 
van_dyCommented:
there are two points to consider:

1) the advantage sysV message queues(msg calls) have over
     posix message queues(mqueue.h) is that  you can read the
      messages from a sysv msg queue in any order you want.
     This can be done by setting priority value for each message.
    posix message queues return the oldest message  on every read.

2) the advantage posix message queues have is that  they allow
     generation of signals when a message a placed in an empty queue.

How are you communicating the indepth info about a particullar client
from process2 to process1 ? will you make  process2 write this extra info
on a client in the message queue itself or will it write this info in a file?

consider

process1:
...//some code
     for(;;) {
                read(STDIN_FILENO, ... read client id you want to get info on
                retreive the record for this client id.
                place a message requesting  more info for this client id in a message queue
               go on to process the record.
          }
      //suppose you read info for a number of clients from the data base , now the user might want
     // the indepth info on say client id x.
         retreive the message with priority x from the message queue..
  .........


process2:
      .. //some code
         for(;;){
                    read message from queue, find the client id.
                   retreive extra info for that client id
                   bundle up the info and mark it with priority = client id. put this info in the message queue
      }

as you can see from above, it will be easier for the process1 to select which client id it wants
the extra info on, and selectively read it from the queue, IF you use sysV msg queues. this wont
bepossible with mqueue.

However if you are writing the extra info in a file, i think  both the queues will work
equally fine.

hope this helps,
van_dy
0
 
bganoushAuthor Commented:

Actually, I shouldn't have closed this...

I was hoping to send the information via the queue in a message. Why isn't it possible for mqueue to do this?

-- Bubba
0
 
bganoushAuthor Commented:

The procedure would look like this:

1) Process 1 sends the client ID to process 2
2) Process 1 returns to the user, not expecting any data from process 2

3) Process 2 retrieves the client ID from the queue
4) Process 2 gets information from various databases and sets up a summary table in a local database.

5) Process 1 sends the client ID to process 2 with a directive to return all data
6) Process 2 picks up the data from the summary table and returns it to Process 1

By what I got from your response, it looks like the problem is that step 6 is not possible with mqueue?  By the way, this communication is pretty synchornous... Process 1 will never ask for more than one client at a time in step 5, and will just sit there until process 2 returns the data in step 6.

-- Bubba
0
 
bganoushAuthor Commented:

One last thing....

Even if the user has asked for info on 20 clients, only one "in depth" package will returned in the queue at any given time, the one the user is currently working with.

-- Bubba
0
 
van_dyCommented:
hmm,
        It seems like that the problem at hand is simpler
than what i thought.

>> I was hoping to send the information via the queue in a message. Why isn't it possible for mqueue to do this?
     Sorry if i implied that somehow. It is very much possible with mqueue to do so.
The point i was making can be explained better with the following figure:

case I:              (oldest message)  ..........................................................................(latest message)                      
[msg-sysV]---->[msg1, p1]----->[msg2, p2]------>[msg3, p3]------>[msg4, p4]----->[msg5, p5]


caseII:                 (oldest message)..........................................................................(latest message)
[mqueue-posix]------>[msg1]-------->[msg2]-------->[msg3]--------->[msg4]--------->[msg5]

     In sysV msg queues, you have a priority value associated with each message(p1, p2 ..), while there is no priority
value associated with mqueue messages.  to read a message from caseI, you can specify a priority value to
the msgget() function and the relevant message will be obtained from the queue. however when u call mq_read()
(I am not very sure if this is the name of the function to read message from posix queues), only the oldest message
from the mqueue, in our case msg1, is returned(you dont have the control over how u read from the queue).


>>By what I got from your response, it looks like the problem is that step 6 is not possible with mqueue?
    I would suggest  you to use 2 message queues.
queue1: dedicated for communicating client ids from process1 to process2.
queue2: dedicated for communicating extra client info from process2 to process1.

so basically
1) process1 writes client-id as a message in the queue1
2) process2 is blocked reading on queue1. when a message is put, it returns with the message. this message will
    contain the client id. then process2 will do its bit with the databases and summary table retreiving all the relevant
    info on the clint-id.
3)  process2 will bundle up all the info in a message and mark it with priority = client-id. then it will place this
     message in queue2.
4)  process1 will read from queue2. knowing that it will contain information on various client-ids, proces1 will
      specify a priority = client-id, to retreive the extra info on a particullar client-id. (this is where sysV are better).

This was the model i was suggesting earlier. However, your problem is pretty synchronous and i gather things
happen like this

user gives client-id--->process1 gets some data on client id, prints it to user, puts the client id in a queue --> process2
retreives the message from queue-->gets all the info and stores it in summary table--> process2 blocks reading on the
queue once again--->process1 writes a client id in the queue-> process2 checks if it has the info on the client id in
the summary table, if it is there it bundles up all the info in a message and puts the message in the queue for process1
to read.

in that case one single message queue will suffice, and it can be just  either of the two , msg or mqueue.

hope it helps,
van_dy









0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now