473,750 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ThreadPool and contacting remote resources

Hello group:

I have a quick question.

Background:
I have an assembly that is responsible for handling our clients' *requests*
(not a webservice/http request per se but our concept of a request --
meaning 'request for our service') thru our webservice. Depending on the
type of client request, we may have to contact an outside provider thru a
WebRequest/WS-method, DCOM, etc... The way it works currently is to handle
all the request parsing/db work/etc. in the main thread, and, if any
outside requests are required, start a thread to handle them. The client's
webmethod response is not dependent on the 'outside' request completing
(some of them can take a few seconds and the client could pair several of
these together so we don't want their response to be waiting on the
completion of these outside calls) so we just return a webmethod response
saying 'we recieved the request, this, that and the other thing'. The
system has been up and running in this fashion for 2 years and threading
deadlocks/contention is not an issue under the current system load.

Recently, we re-wrote this portion of the system to reflect better
efficiency and I'm to the part where I spawn these 'outside' requests. Due
to an increase in business, we have had to offer additional business
services all featured under the same server (to use the branding of the
domain name) because of the SSL cert being paired to the ws address and, for
the first time, server resources have started to become an issue. Hence the
need for the rewrite.

Question: Should I be queuing these 'outside' requests in the ThreadPool?
I know that the ThreadPool class is used internally by various .NET classes.
I would guess that a possible race condition could occur if our client's
request happened at a time when the ThreadPool's max threads are close to
full utilization and their request would require the runtime to use
ThreadPool threads to service a webrequest exceeding the max threads in the
pool. Does anyone know if this is true? By and large, the client requests
complete quickly enough that this *probably* wouldn't occur, but, in the
interest of shoring up my application as well as servicing increased
business, it could potentially occur. We cannot limit the client service
requests in any way (business requirement).

What is the best way to handle this situation?

Thanks all,

Alex

Nov 16 '05 #1
3 1985
I would have one object that is your ClientWorker. That contains its own
thread. ClientWorker will also have a blocking bounded buffer (cQueue) that
listener puts requests into. Your worker thread will block waiting for an
Enqueue (i.e. data to work on.) Then your not messing with threadpool and
delegates, etc. You have one thread that goes full blast picking off
objects and sending replies. If you needed other async work within the
worker (such as name lookups, etc) you could use thread pool - this would
all depend on what your doing and not enouph info yet to know. Anyway see
http://www.codeproject.com/csharp/Bo...ckingQueue.asp for an example
network/listener/worker using this queue method. hth

--
William Stacey, MVP

"Trebek" <al********@int heformofaquesti on.com> wrote in message
news:i5******** **********@fe37 .usenetserver.c om...
Hello group:

I have a quick question.

Background:
I have an assembly that is responsible for handling our clients' *requests* (not a webservice/http request per se but our concept of a request --
meaning 'request for our service') thru our webservice. Depending on the
type of client request, we may have to contact an outside provider thru a
WebRequest/WS-method, DCOM, etc... The way it works currently is to handle all the request parsing/db work/etc. in the main thread, and, if any
outside requests are required, start a thread to handle them. The client's webmethod response is not dependent on the 'outside' request completing
(some of them can take a few seconds and the client could pair several of
these together so we don't want their response to be waiting on the
completion of these outside calls) so we just return a webmethod response
saying 'we recieved the request, this, that and the other thing'. The
system has been up and running in this fashion for 2 years and threading
deadlocks/contention is not an issue under the current system load.

Recently, we re-wrote this portion of the system to reflect better
efficiency and I'm to the part where I spawn these 'outside' requests. Due to an increase in business, we have had to offer additional business
services all featured under the same server (to use the branding of the
domain name) because of the SSL cert being paired to the ws address and, for the first time, server resources have started to become an issue. Hence the need for the rewrite.

Question: Should I be queuing these 'outside' requests in the ThreadPool?
I know that the ThreadPool class is used internally by various .NET classes. I would guess that a possible race condition could occur if our client's
request happened at a time when the ThreadPool's max threads are close to
full utilization and their request would require the runtime to use
ThreadPool threads to service a webrequest exceeding the max threads in the pool. Does anyone know if this is true? By and large, the client requests complete quickly enough that this *probably* wouldn't occur, but, in the
interest of shoring up my application as well as servicing increased
business, it could potentially occur. We cannot limit the client service
requests in any way (business requirement).

What is the best way to handle this situation?

Thanks all,

Alex


Nov 16 '05 #2
Hi Alex,
Question: Should I be queuing these 'outside' requests in the ThreadPool?
I know that the ThreadPool class is used internally by various .NET classes.
I would guess that a possible race condition could occur if our client's
request happened at a time when the ThreadPool's max threads are close to
full utilization and their request would require the runtime to use
ThreadPool threads to service a webrequest exceeding the max threads in the
pool. Does anyone know if this is true? By and large, the client requests
complete quickly enough that this *probably* wouldn't occur, but, in the
interest of shoring up my application as well as servicing increased
business, it could potentially occur. We cannot limit the client service
requests in any way (business requirement).


We were unsucessfully using the ThreadPool in conjuction
with the HttpWebRequest class. HttpWebRequest uses the ThreadPool
itself and doesn't cope at all when the pool is going out
of threads. Instead of accepting that the request has to be
queued, HttpWebRequest throws an exception (.NET 1.1).
We end up implementing our own thread pool.

Bye
Rob
Nov 16 '05 #3
Thank you both ... I'll look into that sample.
Alex

"Trebek" <al********@int heformofaquesti on.com> wrote in message
news:i5******** **********@fe37 .usenetserver.c om...
Hello group:

I have a quick question.

Background:
I have an assembly that is responsible for handling our clients' *requests* (not a webservice/http request per se but our concept of a request --
meaning 'request for our service') thru our webservice. Depending on the
type of client request, we may have to contact an outside provider thru a
WebRequest/WS-method, DCOM, etc... The way it works currently is to handle all the request parsing/db work/etc. in the main thread, and, if any
outside requests are required, start a thread to handle them. The client's webmethod response is not dependent on the 'outside' request completing
(some of them can take a few seconds and the client could pair several of
these together so we don't want their response to be waiting on the
completion of these outside calls) so we just return a webmethod response
saying 'we recieved the request, this, that and the other thing'. The
system has been up and running in this fashion for 2 years and threading
deadlocks/contention is not an issue under the current system load.

Recently, we re-wrote this portion of the system to reflect better
efficiency and I'm to the part where I spawn these 'outside' requests. Due to an increase in business, we have had to offer additional business
services all featured under the same server (to use the branding of the
domain name) because of the SSL cert being paired to the ws address and, for the first time, server resources have started to become an issue. Hence the need for the rewrite.

Question: Should I be queuing these 'outside' requests in the ThreadPool?
I know that the ThreadPool class is used internally by various .NET classes. I would guess that a possible race condition could occur if our client's
request happened at a time when the ThreadPool's max threads are close to
full utilization and their request would require the runtime to use
ThreadPool threads to service a webrequest exceeding the max threads in the pool. Does anyone know if this is true? By and large, the client requests complete quickly enough that this *probably* wouldn't occur, but, in the
interest of shoring up my application as well as servicing increased
business, it could potentially occur. We cannot limit the client service
requests in any way (business requirement).

What is the best way to handle this situation?

Thanks all,

Alex


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3370
by: AA | last post by:
Why microsoft make so hard to change the max Pool Size?? I really need to change it to 50, because I'm using delegates with BeginInvoke and I saw that they (delegates) use the ThreadPool, but I saw too that is very complicate to change the ThreadPool size and if I want, I need to use unmanage resources http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201 If I use unmanage resources my application will not be portable...
13
5657
by: Tamir Khason | last post by:
Is there "standart" way to use more then one threadpool in one process? I mean, without custom developed classes, native way?? Thank you -- Regards, Tamir Khason Especially those days you need a flexible IT service provider that can meet your needs through a broad set of offerings.
5
1703
by: Peter Kirk | last post by:
Hi, I see in the ThreadPool documentation that the pool has a default limit of 25 threads. Is it correctly understood that this limit is for my entire application? So if I have several worker-threads each using "ThreadPool.QueueUserWorkItem" then the limit is spread over all my worker-threads - so if "worker-thread-1" currently has 20 calls in progress then there are only 5 thread-pool threads available for "worker-thread-2" ?
4
2499
by: objectref | last post by:
hi to all folks here, let's say that i am using a threadpool and somehow, some threads in it just stuck. (endless loop or something like that). So, if it receive a request to run for 25 times something that will stuck, it simply will not be able to take more request to dispatch as it will wait for a thread to become available, (due to 25 thread limit) something that in this example is not goint to
8
4903
by: mabra | last post by:
Hi All ! Sorry, I could not find it :-( If the threadpool would be per application domain, I could just create another AppDomain to get another ThreadPool there. Alternately, I would have to opt to some free ThreadPool implementations. Any help would be great! Thanks so far and
3
2308
by: Kevin | last post by:
Using this: http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx as an example I have a question concerning the reuse of objects. In the example 10 instances of the Fibonacci class are made and then all put in the threadpool at once, which is well within the limits of the threadpool. However, what happens if you want to do 10,000 Fibonacci calculations
5
6592
by: FP | last post by:
Hi, i'm currently developing a class to communicate with a serial device,using the SerialPort component. Basically,the main application will interact with this class through its method "Call",the class itself will handle all the details of a call (AT commands included). My problem is that i dont want the application to hang while i'm interacting with the modem,so i have started to learn about threading. Many people have suggested me to...
7
1636
by: Curious | last post by:
On Jun 10, 3:32 am, <s...@dailycoding.comwrote: Thanks! I'll use thread pool.
1
1400
by: Shree | last post by:
On Aug 22, 1:01 pm, "Brian Stoop" <b.st...@consultant-spam.free.com> wrote: A simple way could be to keep a static counter which can be updated in the call back function "TestThread1". Make the main thread wait while this counter is not maxed out; 10 in your case.
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4713
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.