473,382 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

HttpWebRequest and Multi Threaded Apps

Hi,

Im in the process of writing a program that crawls a website. Im using the
HttpWebRequest and HttpWebResponse classed to get content. To make my
application more scalable, my application is multithreaded, with each thread
making a different request.

One problem Ive ran into is that when writing the response stream to the
filesystem, from the HttpWebResponse.GetResponseStream() method, if the
response is of a sufficient size, it blocks all other other executing
threads. If this exceeds the timeout, then all the other threads that are in
the process of making a Web Request time out.

Ive taken every effort to ensure that my application is not locking, I was
wondering if given the scenario that Ive listed, would using Asynchronous Web
Requests be more efficient? Ive not worked with them before so Id be grateful
of your opinions.

Cheers,

Mark

Nov 22 '05 #1
5 5896
hB
you are using different instances of httpwebrequest-response objects in
different threads?
i mean resources should be independent of eachother in all threads.

---
hB

Nov 22 '05 #2
Hi,

Im creating new instances of HttpWebRequest and HttpWebResponse in each
thread. The threads are not sharing requests and responses. Im also not using
the ThreadPool, so Im avoiding issues where Im running out of threads.
Instead Im using Stephen Toubs ManagedThreadPool.

Cheers,

Mark
"hB" wrote:
you are using different instances of httpwebrequest-response objects in
different threads?
i mean resources should be independent of eachother in all threads.

---
hB

Nov 22 '05 #3
hB
Request and response objects are used together.

For example:
HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
HttpWResp.Close();

You get Response Object from the request one.

So for one thread doing HTTPWebRequest Object do HTTPWebResponse work
in same thread.
For multithreading do separate Requests.
Break Threads like
http://example.com/sec1 (req-resp)
http://example.com/sec2 (req-resp)
....

---
hB

Nov 22 '05 #4
hB
Request and response objects are used together.

For example:
HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
HttpWResp.Close();

You get Response Object from the request one.

So for one thread doing HTTPWebRequest Object do HTTPWebResponse work
in same thread.
For multithreading do separate Requests.
Break Threads like
http://example.com/sec1 (req-resp)
http://example.com/sec2 (req-resp)
....

---
hB

Nov 22 '05 #5
Hi,

Thanks for the response. Yep thats what Im currently implenting. Each active
thread makes one Http Request and gets the response.

I do find that I have occasional problems, when reading the response stream.
I find that when calling Stream.Read() this sometimes times out with the
following exception:

Message: The operation has timed out
Stack Trace: at System.ConnectStream.Read(...)

Now it doesnt matter if I set HttpRequest.Timeout = 10000 or 100000, I still
occasionally get these timeouts. When I debug the application its like the
thread is in the process of reading bytes part of the way through and then
hangs.

I can provide code if requested, but I was wondering if anyone else has seen
symptoms like this, and if they could suggest a remedy.

Thanks,

Mark


"hB" wrote:
Request and response objects are used together.

For example:
HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
HttpWResp.Close();

You get Response Object from the request one.

So for one thread doing HTTPWebRequest Object do HTTPWebResponse work
in same thread.
For multithreading do separate Requests.
Break Threads like
http://example.com/sec1 (req-resp)
http://example.com/sec2 (req-resp)
....

---
hB

Nov 22 '05 #6

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

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
0
by: Ganbold | last post by:
Hi, I'm new to multi-threaded programming and reading the book "Programming with POSIX Threads" and trying to understand concepts and coding. What I'm trying to do is to rewrite mysql client...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
2
by: Michal Przytulski | last post by:
Hi, I'm looking information abouth runing PHP CLI application in multi-threaded - on http://www.php.net/manual/pl/ref.pcntl.php i found information abouth process control - but is PHP support...
4
by: Mark Fletcher | last post by:
Hi, Im in the process of writing a program that crawls a website. Im using the HttpWebRequest and HttpWebResponse classed to get content. To make my application more scalable, my application is...
5
by: Rob Durant | last post by:
Hi, I have a multi-threaded application (have also tried as service - same behaviour) that runs fine on XP, but not on 2003. Symptoms are: Threads are started normally, locks acquired and...
1
by: Mullin Yu | last post by:
As subject. I have lots of VB6 dll and ocx files and they are single-threaded as VB6 doesn't support multi-threaded indeed. Can I wrap anything at .NET so that multi-threaded feature can be...
6
by: Leon | last post by:
Hi there, I am trying to use the WebBrowser Control in a form which is being started in an own thread by the main form of my application. Unfortunately I am always getting an error in...
2
by: eBob.com | last post by:
I get no error pop-ups from my multi-threaded application. This makes it difficult to find errors. Fortunately I can step statement by statement though code running under any thread - but that's...
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.