Re: HttpListener BeginGetContext does not seem to handle more than 2 request simultaneously
- From: "Vadym Stetsyak" <vadym_s@xxxxxxx>
- Date: Wed, 3 Jan 2007 10:57:49 +0200
Hello, Kunal!
I think there is a memory leak some where in your code.
Have a look at (
http://msdn.microsoft.com/msdnmag/issues/06/11/CLRInsideOut/default.aspx?loc=en )
to do the memory issue investigation.
You wrote on 29 Dec 2006 12:53:40 -0800:
K> Hi Vadym,
K> After the change you suggested, my server ran just fine and seemed to
K> be aceepting/processing multiple requests simultaneously. However,
K> after a few hours of operation (when there are about 15 clients
K> coming
K> in per second) the
K> server crashed with the followin exception -
K> System.OutOfMemoryException: Exception of type
K> 'System.OutOfMemoryException' was thrown.
K> Server stack trace:
K> at System.Net.RequestContextBase.SetBuffer(Int32 size)
K> at System.Net.AsyncRequestContext.Allocate(UInt32 size)
K> at System.Net.HttpListener.BeginGetContext(AsyncCallback callback,
K> Object state)
K> at HttpListenerLibrary.HttpListenerWrapper.ProcessRequest() in
K> C:\StarTeam\easycare\Software\Release\SimulatorsDev\AcsSim\
K> HttpListenerLibrary\HttpListenerLibrary.cs:line
K> 260
K> at
K> System.Runtime.Remoting.Messaging.StackBuilderSink._
K> PrivateProcessMessage(IntPtr
K> md, Object[] args, Object server, Int32 methodPtr, Boolean
K> fExecuteInContext, Object[]& outArgs)
K> at
K> System.Runtime.Remoting.Messaging.StackBuilderSink.
K> PrivateProcessMessage(RuntimeMethodHandle
K> md, Object[] args, Object server, Int32 methodPtr, Boolean
K> fExecuteInContext, Object[]& outArgs)
K> at
K> System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(
K> IMessage
K> msg, Int32 methodPtr, Boolean fExecuteInContext)
K> Exception rethrown at [0]:
K> at
K> System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(
K> IMessage
K> reqMsg, IMessage retMsg)
K> at
K> System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
K> msgData, Int32 type)
K> at HttpListenerLibrary.HttpListenerWrapper.ProcessRequest()
K> at HttpListenerLibrary.HttpListenerController.Pump() in
K> C:\StarTeam\easycare\Software\Release\SimulatorsDev\AcsSim\
K> HttpListenerLibrary\HttpListenerLibrary.cs:line
K> 166
K> There was this event also in the event log -
K> Exception information:
K> Exception type: OutOfMemoryException
K> Exception message: Exception of type
K> 'System.OutOfMemoryException'
K> was thrown.
K> Thread information:
K> Thread ID: 7
K> Thread account name: CPEPR1\Administrator
K> Is impersonating: False
K> Stack trace: at System.Web.HttpRequest.GetEntireRawContent()
K> at System.Web.HttpRequest.get_InputStream()
K> at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
K> at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type
K> type, HttpContext context, HttpRequest request, HttpResponse
K> response,
K> Boolean& abortProcessing)
K> at
K> System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(
K> Type
K> type, HttpContext context, HttpRequest request, HttpResponse
K> response)
K> at
K> System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(
K> HttpContext
K> context, String verb, String url, String filePath)
K> at System.Web.HttpApplication.MapHttpHandler(HttpContext context,
K> String requestType, VirtualPath path, String pathTranslated, Boolean
K> useAppConfig)
K> at
K> System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.
K> HttpApplication.IExecutionStep.Execute()
K> at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
K> Boolean& completedSynchronously)
K> Do you think the server is not getting enough memory to process
K> further
K> requests ? from the exception it looks like while trying to allocate
K> buffers for storing the incoming request it fails. But this is within
K> the stack area. How can this be debugged ? How can I find out what
K> are
K> the resources occupying memory at that time ?
K> Thanks,
K> Kunal
K> On Dec 26, 10:55 pm, "Kunal" <koolku...@xxxxxxxxx> wrote:
Hi Vadym,
Thanks for your suggestion. This change seems to work for me.
However, what is the best way of determining how many concurrent
connections
my server is handling at any instant ? And how to make sure any
connections
are not being refused or dropped ?
In my code, there's one change I tried but that threw an exception.
Instead of
calling ProcessRequest in the infinite while loop, I call it just
once.
Then within
the ListenerCallback, I setup a new BeginGetContext just after the
call
to
EndGetContext, to set up a loop. But I got an exception related to a
thread
exit at the time of call.
Do you think the current while loop is just fine and I need not try
out
this new
way ? I saw this implementation technique somewhere and was curious to
try
it out.
Thanks for all your time,
Regards,
Kunal
On Dec 22, 1:54 pm, "Vadym Stetsyak" <vady...@xxxxxxx> wrote:
Hello, Kunal!
line "result.AsyncWaitHandle.WaitOne();"
blocks in ProcessRequest method thus breaking the async execution.
Try to comment that line an repeat your tests.
You wrote on 21 Dec 2006 14:41:15 -0800:
K> Hi Friends,
K> I'm trying to host a webservice that will receive/processmultiple
K> client requests simultaneously. For this purpose, I wrote thetime. I
K> following
K> code, but it does not seem to be handling more than two at a
K> put in a few console prints and have also attached the output.Here
K> it
K> goes -
K> public void serverStart() {
K> HttpListener _listener = new HttpListener();
K> _listener.Prefixes.Add(.......);
K> _listener.Start();
K> while (true)
K> ProcessRequest();
K> }
K> public void ProcessRequest()
K> {
K> Console.WriteLine("PR " + ++count); //count initialized to 0in
K> beginning
K> IAsyncResult result = _listener.BeginGetContext(newAsyncCallback
K> ListenerCallback),this._listener);
K> result.AsyncWaitHandle.WaitOne();
K> }
K> protected void ListenerCallback(IAsyncResult result)
K> {
K> if (this._listener == null) return;
K> HttpListenerContext context =
K> this._listener.EndGetContext(result);
K> Console.WriteLine("LC " + count);
K> this.ProcessRequest2(context);
K> }
K> public void ProcessRequest2(HttpListenerContext ctx)
K> {
K> Console.WriteLine("PR2 " + count);
K> string str = ctx.Request.HttpMethod;
K> HttpListenerWorkerRequest workerRequest =
K> new HttpListenerWorkerRequest(ctx,_virtualDir, _physicalDir,
K> _logCallback, _pxeb);
K> HttpRuntime.ProcessRequest(workerRequest);
K> }
K> The output this gives me looks like this -
K> PR 1
K> PR 2
K> LC 2
K> PR2 2
K> LC 2
K> PR2 3
K> PR 3
K> LC 3
K> PR2 4
K> PR 4
K> LC 4
K> PR2 5
K> PR 5
K> PR 6
K> LC 6
K> PR2 6
K> LC 6
K> PR2 7
K> PR 7
K> PR 8
K> LC 8
K> PR2 8
K> PR 9
K> LC 9
K> PR2 9
K> LC 9
K> Can someone point out what's happening ? The Microsoftdocumentation
K> does not say anything about the no. of connections this model can
K> handle or has a limit to. Any developers who have used this may
K> please
K> enlighten me !
K> Thanks and Regards,
K> Kunal
With best regards, Vadym Stetsyak.text -
Blog:http://vadmyst.blogspot.com- Hide quoted text -- Show quoted
With best regards, Vadym Stetsyak.
Blog: http://vadmyst.blogspot.com
.
- Prev by Date: Re: Custom configuration section: How to get null for non required properties?
- Next by Date: Re: Custom configuration section: How to get null for non required properties?
- Previous by thread: Q : WebClient.DownloadData not working for HTTPS page through a PROXY
- Next by thread: Referencing controls inside FormView
- Index(es):
Relevant Pages
|