By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,933 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,933 IT Pros & Developers. It's quick & easy.

Parallel Programming

P: n/a
I have a program that needs to run on a regular basis that looks at a
queue table in my database. If there are items in the queue database
I need to grab the data from the database and pass it to a web service
to process. The web service will return either a completion code or
error msg (the only errors expected would be timeout or cannot
connection errors). This queue file can contain 0 to N messages.
Naturally if there are no messages the program terminates. If there
are less than 8 messages in the queue, I will run the program on a
single thread waiting for a response. However, if there are more than
8 messages (indicating a backlog) I would like to process them in
parallel through the server's 8 cores. I have been reading up on the
parallel library and it looks promising. My questions are:

1. Would the parallel processing library be appropriate for this
situation? Could web services be invoked on each "thread" created and
processed?

2. How would I make sure not to access the same record in the
database? I can return a listing of all the queueID's from the
database and pass them in as a parameter (looking a the Parallel.For
or Parallel.Foreach?

3. If this is not a good path to pursue, what other options do you
suggest? I was thinking of threading and calling the services on an
async method, but this has its own issues.

Thanks.

John
Oct 9 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hey that program sounds familiair :-)

I have created a program that does exactly what you describe and a bit more
only with that difference that mine is always running in paralel modus
my program is a service by itself ( a windows service ) it checks every 500
miliseconds + N processing seconds if there is anny work to be done ,
if there is work availlable it will create a instance of a worker assembly
( dll with queue interface ) in a seperate thread .
1. Would the parallel processing library be appropriate for this
situation?
Don`t know i created the logic all myself , and it was not that hard + the
extra benefit is that i fully understand what is happening and have full
control
Could web services be invoked on each "thread" created and processed?
Yes as IIS is also multithreaded and webservices are stateless
>2. How would I make sure not to access the same record in the
database? I can return a listing of all the queueID's from the
database and pass them in as a parameter (looking a the Parallel.For
or Parallel.Foreach?
My queue table has a status byte so 0 is in wait modus , 1 is in process
modus , 2 is in cancell modus , 3 is in error state , 4 is finished
however the record is then also removed from the table
3. If this is not a good path to pursue, what other options do you
suggest? I was thinking of threading and calling the services on an
async method, but this has its own issues.
Yes i guess it is , in our production environment it is working this way
since early 2006 the project is recently upgraded to VB 2008 framework 3.5
>I was thinking of threading and calling the services on an
async method, but this has its own issues.
I run my worker objects in a seperate thread als code is encapsulated in a
worker class that implements my queue interface it can comunicate with my
main assembly although it is running in a fire and forget modus on a
seperate thread context , my queue server can run multiple queues
simultaniously

this requires a good interface definition hoever it means that you can write
all your worker code in a "normall" fashion as the whole running object is
in a seperate running thread context .

In my opinion you are on the right path , as it sounds so familiair to
my project i would be a fool to say otherwise ( maybe my boss is reading
this :-) )
are you sure you are not also working for the ista corporation
http://www.ista.com :-)

However so many people so many aproaches for the same task so maybe someone
else has a brighter idea to acomplish this task

HTH

Michel Posseth [MCP]
http://www.vbdotnetcoder.com


"John" <ri**********@hotmail.comschreef in bericht
news:e3**********************************@f63g2000 hsf.googlegroups.com...
>I have a program that needs to run on a regular basis that looks at a
queue table in my database. If there are items in the queue database
I need to grab the data from the database and pass it to a web service
to process. The web service will return either a completion code or
error msg (the only errors expected would be timeout or cannot
connection errors). This queue file can contain 0 to N messages.
Naturally if there are no messages the program terminates. If there
are less than 8 messages in the queue, I will run the program on a
single thread waiting for a response. However, if there are more than
8 messages (indicating a backlog) I would like to process them in
parallel through the server's 8 cores. I have been reading up on the
parallel library and it looks promising. My questions are:

1. Would the parallel processing library be appropriate for this
situation? Could web services be invoked on each "thread" created and
processed?

2. How would I make sure not to access the same record in the
database? I can return a listing of all the queueID's from the
database and pass them in as a parameter (looking a the Parallel.For
or Parallel.Foreach?

3. If this is not a good path to pursue, what other options do you
suggest? I was thinking of threading and calling the services on an
async method, but this has its own issues.

Thanks.

John

Oct 9 '08 #2

P: n/a
On Oct 9, 1:59*pm, "Michel Posseth [MCP]" <M...@posseth.comwrote:
Hey that program sounds familiair :-)

I have created a program that does exactly what you describe and a bit more
only with that difference that mine is always running in paralel modus
my program is a service by itself ( a windows service ) *it checks every 500
miliseconds + *N processing seconds *if there is anny work to be done,
if there is work availlable it will create a instance of a worker assembly
( dll with queue interface ) in a seperate thread *.
1. *Would the parallel processing library be appropriate for this
situation?

Don`t know i created the logic all myself , and it was not that hard + the
extra benefit is that i fully understand what is happening and have full
control
Could web services be invoked on each "thread" created and processed?

Yes as IIS is also multithreaded and webservices are stateless
2. *How would I make sure not to access the same record in the
database? *I can return a listing of all the queueID's from the
database and pass them in as a parameter (looking a the Parallel.For
or Parallel.Foreach?

My queue table *has a status byte *so 0 is in wait modus , 1 is in process
modus , *2 is in cancell modus , 3 is in error state *, 4 is finished
however the record is then also removed from the table
3. *If this is not a good path to pursue, what other options do you
suggest? *I was thinking of threading and calling the services on an
async method, but this has its own issues.

Yes i guess it is , in our production environment it is working this way
since early 2006 the project is recently upgraded to VB 2008 *framework3.5
I was thinking of threading and calling the services on an
async method, but this has its own issues.

I run my worker objects in a seperate thread als code is encapsulated in a
worker class that implements my queue interface it can comunicate with my
main assembly although it is running in a fire and forget modus on a
seperate thread context , my queue server *can run multiple queues
simultaniously

this requires a good interface definition hoever it means that you can write
all your worker code in a "normall" fashion as the whole running object is
in a seperate running thread context .

In my opinion you are on the right path * , as it sounds so *familiair *to
my project *i would be a fool to say otherwise ( maybe my boss is reading
this :-) *)
are you sure you are not also working *for the ista corporationhttp://www.ista.com*:-)

However so many people so many aproaches for the same task so maybe someone
else has a brighter idea to acomplish this task

HTH

Michel Posseth [MCP]http://www.vbdotnetcoder.com

"John" <riley_wri...@hotmail.comschreef in berichtnews:e3**********************************@f 63g2000hsf.googlegroups.com...
I have a program that needs to run on a regular basis that looks at a
queue table in my database. *If there are items in the queue database
I need to grab the data from the database and pass it to a web service
to process. *The web service will return either a completion code or
error msg (the only errors expected would be timeout or cannot
connection errors). *This queue file can contain 0 to N messages.
Naturally if there are no messages the program terminates. *If there
are less than 8 messages in the queue, I will run the program on a
single thread waiting for a response. *However, if there are more than
8 messages (indicating a backlog) I would like to process them in
parallel through the server's 8 cores. *I have been reading up on the
parallel library and it looks promising. *My questions are:
1. *Would the parallel processing library be appropriate for this
situation? *Could web services be invoked on each "thread" created and
processed?
2. *How would I make sure not to access the same record in the
database? *I can return a listing of all the queueID's from the
database and pass them in as a parameter (looking a the Parallel.For
or Parallel.Foreach?
3. *If this is not a good path to pursue, what other options do you
suggest? *I was thinking of threading and calling the services on an
async method, but this has its own issues.
Thanks.
John- Hide quoted text -

- Show quoted text -
Ha, great minds think alike! I to have a status field on my queue
that will change as it progresses through the system. I plan on
making a windows service as well to monitor the queue. Most of the
time if the central system is up and running the queue will never be
full since we want this near real time. However, in those rare
instances when the connection is severed or they roll the main system
back I can re-queue jobs and have them automatically push up again.
Looking at my options, the Parallel class has not fully matured and is
still in CTP state, so I am going to do my own threading. I think
I'll check the number of items in the queue and spawn threads
accordingly with a thread limit to eliminate overloading the server.
Thanks for the encouragement, and no I don't work at ista, but if they
paid enough I just might!

Thanks.
Oct 9 '08 #3

P: n/a
John,

As I made this as well a short while ago in a windows service, is it quite
simple to do in a webservice as well.

The only thing I did, was not using anything to make a difference between 8
or 9.

I simple use in this kind of problems forever the generic Queue class. It
does exactly what is needed to create smooth operations in multithreading

http://msdn.microsoft.com/en-us/library/7977ey2c.aspx

Don't forget to synclock between enqueing and dequing.

Cor

"John" <ri**********@hotmail.comschreef in bericht
news:e3**********************************@f63g2000 hsf.googlegroups.com...
>I have a program that needs to run on a regular basis that looks at a
queue table in my database. If there are items in the queue database
I need to grab the data from the database and pass it to a web service
to process. The web service will return either a completion code or
error msg (the only errors expected would be timeout or cannot
connection errors). This queue file can contain 0 to N messages.
Naturally if there are no messages the program terminates. If there
are less than 8 messages in the queue, I will run the program on a
single thread waiting for a response. However, if there are more than
8 messages (indicating a backlog) I would like to process them in
parallel through the server's 8 cores. I have been reading up on the
parallel library and it looks promising. My questions are:

1. Would the parallel processing library be appropriate for this
situation? Could web services be invoked on each "thread" created and
processed?

2. How would I make sure not to access the same record in the
database? I can return a listing of all the queueID's from the
database and pass them in as a parameter (looking a the Parallel.For
or Parallel.Foreach?

3. If this is not a good path to pursue, what other options do you
suggest? I was thinking of threading and calling the services on an
async method, but this has its own issues.

Thanks.

John
Oct 10 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.