473,624 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asynchronous webrequest taking 100 % CPU usage

Hi all
i am having application which is using asychronous web request.

At a time i am processing 5 urls asynchronously.

Application working properly for 5 asynchronous call. But sometimes CPU
usage suddently increases to 100 %.

Can some one tell me why this is happening.

Any help will be truely appreciated.

thanks in advance.

Dec 7 '05 #1
5 5583
Hi Archana,

Web Requests are allways synchronous.

This may be a bit a shocking answer but remember that the http protocol
allways need a response 200 Ok or some kind or error.
So lets say you use Javascript to do a post towards a webservice using the
asynch switch. Although your code will continue to run untill the event
requestcomplete (or something like that) hits.

The line towards the webserver will remain open.

If you really want to be asynchronous using the web start the server side
processes in seperate treads. I think IE is looping through it's open
connections increasing the CPU load to 100% This is when I found out the
lines remained open :-)

Hope this helped.

Kind regards,

--
Rainier van Slingerlandt
(Freelance trainer/consultant/developer)
www.slingerlandt.com
"archana" wrote:
Hi all
i am having application which is using asychronous web request.

At a time i am processing 5 urls asynchronously.

Application working properly for 5 asynchronous call. But sometimes CPU
usage suddently increases to 100 %.

Can some one tell me why this is happening.

Any help will be truely appreciated.

thanks in advance.

Dec 7 '05 #2
Hi

thanks for your reply.

I am using webrequest class sychronously. And i have C# desktop based
application. Not using any server side scripting. In MSDN , one
example is giving for making asynchronous request. That i am using
which is taking lots of cpu usage if i increase asynchronous request
from 1 to 5 request.

I hope you will get my problem.

Thanks
Rainier [MCT] wrote:
Hi Archana,

Web Requests are allways synchronous.

This may be a bit a shocking answer but remember that the http protocol
allways need a response 200 Ok or some kind or error.
So lets say you use Javascript to do a post towards a webservice using the
asynch switch. Although your code will continue to run untill the event
requestcomplete (or something like that) hits.

The line towards the webserver will remain open.

If you really want to be asynchronous using the web start the server side
processes in seperate treads. I think IE is looping through it's open
connections increasing the CPU load to 100% This is when I found out the
lines remained open :-)

Hope this helped.

Kind regards,

--
Rainier van Slingerlandt
(Freelance trainer/consultant/developer)
www.slingerlandt.com
"archana" wrote:
Hi all
i am having application which is using asychronous web request.

At a time i am processing 5 urls asynchronously.

Application working properly for 5 asynchronous call. But sometimes CPU
usage suddently increases to 100 %.

Can some one tell me why this is happening.

Any help will be truely appreciated.

thanks in advance.


Dec 8 '05 #3
Rainier [MCT] wrote:
Hi Archana,

Web Requests are allways synchronous.

This may be a bit a shocking answer but remember that the http
protocol allways need a response 200 Ok or some kind or error.


You're confusing asynchronous I/O with connection-oriented protocols.
HTTP isn't synchronous. Nor is it asynchronous. The term just doesn't
apply here.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Dec 9 '05 #4
archana wrote:
Hi all
i am having application which is using asychronous web request.

At a time i am processing 5 urls asynchronously.

Application working properly for 5 asynchronous call. But sometimes
CPU usage suddently increases to 100 %.

Can some one tell me why this is happening.

Any help will be truely appreciated.


Post your code, otherwise it's all just guessing.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Dec 9 '05 #5
Hi

i am posting code of processing url asynchronously.

using System;
using System.Net;
using System.Threadin g;
using System.Text;
using System.IO;

// The RequestState class passes data across async calls.
public class RequestState
{
const int BufferSize = 1024;
public StringBuilder RequestData;
public byte[] BufferRead;
public WebRequest Request;
public Stream ResponseStream;
// Create Decoder for appropriate enconding type.
public Decoder StreamDecode = Encoding.UTF8.G etDecoder();

public RequestState()
{
BufferRead = new byte[BufferSize];
RequestData = new StringBuilder(S tring.Empty);
Request = null;
ResponseStream = null;
}
}

// ClientGetAsync issues the async request.
class ClientGetAsync
{
public static ManualResetEven t allDone = new
ManualResetEven t(false);
const int BUFFER_SIZE = 1024;

public static void Main(string[] args)
{
if (args.Length < 1)
{
showusage();
return;
}

// Get the URI from the command line.
Uri httpSite = new Uri(args[0]);

// Create the request object.
WebRequest wreq = WebRequest.Crea te(httpSite);

// Create the state object.
RequestState rs = new RequestState();

// Put the request into the state object so it can be passed
around.
rs.Request = wreq;

// Issue the async request.
IAsyncResult r = (IAsyncResult) wreq.BeginGetRe sponse(
new AsyncCallback(R espCallback), rs);

// Wait until the ManualResetEven t is set so that the application

// does not exit until after the callback is called.
allDone.WaitOne ();

Console.WriteLi ne(rs.RequestDa ta.ToString());
}

public static void showusage() {
Console.WriteLi ne("Attempts to GET a URL");
Console.WriteLi ne("\r\nUsage:" );
Console.WriteLi ne(" ClientGetAsync URL");
Console.WriteLi ne(" Example:");
Console.WriteLi ne(" ClientGetAsync
http://www.contoso.com/");
}

private static void RespCallback(IA syncResult ar)
{
// Get the RequestState object from the async result.
RequestState rs = (RequestState) ar.AsyncState;

// Get the WebRequest from RequestState.
WebRequest req = rs.Request;

// Call EndGetResponse, which produces the WebResponse object
// that came from the request issued above.
WebResponse resp = req.EndGetRespo nse(ar);

// Start reading data from the response stream.
Stream ResponseStream = resp.GetRespons eStream();

// Store the response stream in RequestState to read
// the stream asynchronously.
rs.ResponseStre am = ResponseStream;

// Pass rs.BufferRead to BeginRead. Read data into rs.BufferRead
IAsyncResult iarRead = ResponseStream. BeginRead(rs.Bu fferRead, 0,

BUFFER_SIZE, new AsyncCallback(R eadCallBack), rs);
}
private static void ReadCallBack(IA syncResult asyncResult)
{
// Get the RequestState object from AsyncResult.
RequestState rs = (RequestState)a syncResult.Asyn cState;

// Retrieve the ResponseStream that was set in RespCallback.
Stream responseStream = rs.ResponseStre am;

// Read rs.BufferRead to verify that it contains data.
int read = responseStream. EndRead( asyncResult );
if (read > 0)
{
// Prepare a Char array buffer for converting to Unicode.
Char[] charBuffer = new Char[BUFFER_SIZE];

// Convert byte stream to Char array and then to String.
// len contains the number of characters converted to Unicode.
int len =
rs.StreamDecode .GetChars(rs.Bu fferRead, 0, read, charBuffer,
0);

String str = new String(charBuff er, 0, len);

// Append the recently read data to the RequestData
stringbuilder
// object contained in RequestState.
rs.RequestData. Append(
Encoding.ASCII. GetString(rs.Bu fferRead, 0, read));

// Continue reading data until
// responseStream. EndRead returns -1.
IAsyncResult ar = responseStream. BeginRead(
rs.BufferRead, 0, BUFFER_SIZE,
new AsyncCallback(R eadCallBack), rs);
}
else
{
if(rs.RequestDa ta.Length>0)
{
// Display data to the console.
string strContent;
strContent = rs.RequestData. ToString();
}
// Close down the response stream.
responseStream. Close();
// Set the ManualResetEven t so the main thread can exit.
allDone.Set();
}
return;
}
}
Only thing is in main instead of processing one url i have one array
containing urls and i am starting processing of url at the same time.

thanks.

Dec 15 '05 #6

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

Similar topics

2
2148
by: Leo | last post by:
Version 7 fixpack 9, aix 5.1 In our database we have a table that that has a dedicated bufferpool for the data, and another for indexes. Actually we have three of these combinations and they all behave the same. Taken from a bufferpool snapshot: Index buffer pool: Asynchronous pool index page reads = 147089
0
1312
by: DotNetShadow | last post by:
Hi Guys I came across this article which deals with Performance Considerations for Making Web Service Calls from ASPX Pages: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service07222003.asp The article talks about 3 approaches synchronous | asyncronous | and PrerequestHandler with asynchronous calls. I tried the sample that came with the article and the concept proves right.
12
2856
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts the query string with no url encoding. I must pass the <> characters as they are in the query string. If these characters are url encoded the service rejects the request. This API Url is http://testing.shippingapis.com/ShippingAPITest.dll
11
1908
by: Dave | last post by:
I'm trying to understand the implications of using static methods and properties in asp.net so I found an article "Troubleshooting ASP.NET applications with the use of static keywords" (http://support.microsoft.com/?id=893666) that discusses the possiblity of users seeing other users data if they access static methods at the same time because values are shared. Although I never used it, I noticed that some SqlHelper functions part of...
0
1111
by: Demi | last post by:
http://msdn2.microsoft.com/en-us/library/21k58ta7.aspx I'm using that example as my starting point. The timeout it has though is not bulletproof. It will timeout if it doesn't connect within the timeout period, but if it connects and the server sends 1 byte and then hangs the connection open, it will not timeout. I'd like to include another timeout (let's say 10 seconds) for the read not finishing (or alternatively a timeout that...
3
2295
by: Maya Sam | last post by:
Hi all, I have the following code I created to do multiple websites data crawling using Asynchronous Thread calling it works fine however I'm confused when it comes to make the calling thread stops or sleep until all other threads within the threadpool have all finished their jobs. what happens at the moment is that every other thread "should" just concatenate string data to public string variable when it finishes, but however the...
0
1411
by: thomasabcd | last post by:
Hi, During the user's registration I wan't to geo-code an address using localsearchmaps.com/geo. For that purpose I use a webrequest like this: string url = "http://www.localsearchmaps.com/geo/?street=" + StreetNumber + "+" + StreetName + "&city=" + City + "&country=DK&google2=1"; System.Net.WebRequest webRequest =
0
1059
by: archana | last post by:
Hi all, I am having application wherein i am processing some asynchronous webrequest. I have declared one timeout callback as specified in MSDN for implementing timeout for aysnchornous web request. I registered this callback by using RegisterWaitForSingleObject But in MSDN this TimeoutCallback function is private static. and my
0
254
by: APA | last post by:
I've seen the MS sample async web request pattern and I ask is it really async if it is using a ManualResetEvent and setting WaitOne()? The ManualResetEvent object is being declared as a static variable so isn't it causing problems with other threads that may be using the same class to execute the async web request? If I remove the ManualResetEvent object will it be truly asynchronous and will I be losing something? Also, in my app the web...
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
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
8680
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
8482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7168
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...
0
5565
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
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1487
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.