ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Custom node to sleep for a while

Post new topic  Reply to topic
 Custom node to sleep for a while « View previous topic :: View next topic » 
Author Message
simon.starkie
PostPosted: Mon Mar 25, 2002 2:28 pm    Post subject: Reply with quote

Disciple

Joined: 24 Mar 2002
Posts: 180

I have been asked to develop a custom node to stop an MQSI message flow when a temporary error occurs (e.g. an MQ Queue is temporarily full). The intent is to put a thread to sleep for a while. I've written and implemented a solution using the sleep(<interval_time>) function. Tests using multiple messages with both short (10 second) and long (60 second) intervals within the SAME execution group have been fully successfull, suggesting there are no thread issues. But

I'm a little worried about whether or not it is OK to use sleep in this manner or should I use something else that is thread-safe (for example, pthread_delay_np)?

Also, can anyone comment on the rumor that all custom nodes needs to be thread safe ? (IMHO, it only matters if you have multiple threads doing things in a co-dependent manner. So I think sleep from within a thread should be safe for that thread and will not affect any other thread. I'm not waiting for a while hoping another thread will finish doing something that I am waiting for).
Cheers.
Back to top
View user's profile Send private message
kolban
PostPosted: Mon Mar 25, 2002 4:47 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2001
Posts: 1072
Location: Fort Worth, TX, USA

From a design perspective, having a message flow sleep goes against all that WMQI was designed for. If the flow sleeps, all the resources associate with that flow are locked up and held waiting. Would you put an EJB to sleep?

If the message flow sleeps, it is possible that control messages may be blocked such as requests to stop the broker or deploy new flows.

If the man page for sleep() says that it is thread safe, you should be ok to use it. If the man page does not say that sleep is safe, then find an alternative such as the select() system call.

Custom nodes mus be thread safe. Although you may get away with it, all bets are off and if something strange happens, it is likely that IBM support will ask about your nodes and some unexpected interaction may be the culprit.
Back to top
View user's profile Send private message
simon.starkie
PostPosted: Wed Mar 27, 2002 9:45 am    Post subject: Reply with quote

Disciple

Joined: 24 Mar 2002
Posts: 180

Thanks.

Yes, I agree. Having a message flow sleep goes against the architectural intent of MQSI, but this is what the customer wants and so I will try to accomodate them.

The man page for select() does not explicitly say it is thread safe. Sigh.
I think I'll use pthread_delay_np.

Thanks for the clarification about custom nodes needing to be thread safe.

Take care.
Back to top
View user's profile Send private message
simon.starkie
PostPosted: Thu Apr 04, 2002 3:50 pm    Post subject: Reply with quote

Disciple

Joined: 24 Mar 2002
Posts: 180

pthread_delay_np seems to work fine. I'll find out one of these days when a decent volume of transactions is processed and the sleep routine gets executed during error triage (i.e. a queue is temporarily full or a database is temporarily down).

I researched the select() that was suggested and found several hits on google indicating select() does not work in AIX environments as expected. Specifically, most of the questions indicated that the timeout did not work. I tested a simple piece of code (see below) and found that it didn't stop executing on my AIX system either:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int main(int argc, char **argv)
{
struct timeval tv = {0, 0};

printf("test startn");

/*select with a delay of 5 seconds */
tv.tv_sec = 5;
tv.tv_nsec = 0;
select(0,0,0,0,tv);

printf("test stopn");
return(0);
}

However, the pthread_delay_np worked as expected. Here is a simple test:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int main(int argc, int **argv)
{
/*
TEST A THREAD SAFE DELAY FUNCTION
*/
char strTime[2];
struct timespec ts = {0, 0};
ts.tv_sec = 0;
ts.tv_nsec = 0;
strcpy(strTime, argv[1]);
ts.tv_sec = atoi(strTime);
printf("test pthread_delay_np for %ld secondsn", ts.tv_sec);
pthread_delay_np(&ts);
return(0);
}

Of course, the custom plugin code is a little more complicated. Basically, I just map the Seconds string attribute to an integer iSeconds (the sleep interval) and the Evaluate routine then passes this to the following doSleep routine:
static int DoSleep(int ts)
{
struct timeval TimeOut;
TimeOut.tv_sec = ts;
TimeOut.tv_usec = 0;
mqsixLog(">> DoSleep for %ld secondsn", ts);
pthread_delay_np(&TimeOut);
mqsixLog("<< DoSleepn");
return;

}

Multiple message flows using different sleep intervals were deployed to a single execution group and they all slept for the correct amount of time.

Thanks again for the help. This forum is an excellent resource for all of us.
:smile:

[ This Message was edited by: simon.starkie on 2002-04-27 14:31 ]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Custom node to sleep for a while
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.