Threadpoollllll!!!! help

  • Thread starter Thread starter ArtOfSpeech
  • Start date Start date
A

ArtOfSpeech

hi,
i have a program that runs multiple (10..12) tasks using threadpool...
the program runs smoothly almost all the time, but it suspends after a
long period of time (like 24 hours or so) for a reason that i cant
figure out!!!

i call the thread using this command:
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
Trigger(i).start))


where trigger is an array of objects of my own


can anyone tell me plz what's wrong with what i am doin!!!??


thx alot in advance
 
Hello, (e-mail address removed)!

A> i call the thread using this command:
A> ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
A> Trigger(i).start))

A> where trigger is an array of objects of my own

A> can anyone tell me plz what's wrong with what i am doin!!!??

How many threads are there in the application, when it is suspended?
Did you try attaching debugger and watch, where actually execution stopped, how many threads are allocated?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Thx for your response Vadym...
i have a timer that loads each minute about 10 threads using
ThreadPool.QueueUserWorkItem...
i dont know how to count threads in my application, or to attach a
debugger to it....
and i am not testing it in the computre where it was created....
thx alot again
 
Hello (e-mail address removed),

Take into account that ThreadPool is limiter up to the 25 threads.
It means if u are using all 25 threads, the next thread will wait till some
of the previous threads finish works

That's why Vadim suggest to check number of active thread.
Thx for your response Vadym...
i have a timer that loads each minute about 10 threads using
ThreadPool.QueueUserWorkItem...
i dont know how to count threads in my application, or to attach a
debugger to it....
and i am not testing it in the computre where it was created....
thx alot again

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
You really need to examine what is going on inside each thread.

For example, if the thread makes a call without a timeout, or has an
endless loop, or long running query, it will tie up a thread for that
amount of time.

Do you have control over the code that is executed /inside/ the threaded
method ( "Trigger" ) ?
 
hi...
yes i do have control....
i do indeed make internet connections inside each of these methods,
with which i might send or recieve files from or to some url... maybe
as you say its a matter of connection timeout...
i'll check the time out there to find whats wrong...
thx alot
 
hi...
yes i do have control....
i do indeed make internet connections inside each of these methods,
with which i might send or recieve files from or to some url... maybe
as you say its a matter of connection timeout...
i'll check the timeout there to find whats wrong...
thx alot
 
hi...
yes i do have control....
i do indeed make internet connections inside each of these methods,
with which i might send or recieve files from or to some url... maybe
as you say its a matter of connection timeout...
i'll check the timeout there to find whats wrong...
thx alot
 
hi,
its me back
i'm calling this function in each of my threads to get some data from a
specific url:

Public Function getResponse(ByVal url As String) As String
Dim TriggerName As String
Dim WebResult As String
Dim Check As Integer
Dim request As HttpWebRequest
Dim response As HttpWebResponse
Dim s As Stream
Dim sr As StreamReader
Try
request = WebRequest.Create(url)
request.Timeout = 10000
response = request.GetResponse()
s = response.GetResponseStream()
sr = New StreamReader(s)
Dim str As String
str = sr.ReadToEnd()
getResponse = str
request.Abort()
response.Close()
s.Close()
sr.Close()
Catch we As WebException
getResponse = ""
Catch ex As Exception
getResponse = ""
Finally
'Try
'request.Abort()
'response.Close()
'request = Nothing
'response = Nothing
'Catch ex As Exception
'End Try
'Try
' sr.Close()
' s.Close()
'Catch ex As Exception
'End Try
End Try
End Function

whats am i doing worng why it doesnt sometimes abort the request???
 
Hello, (e-mail address removed)!

What do you want to abort?
You call request.Abort() after you've got the response, IMO there is nothing to abort there.

HttpWebRequest.Abort(...) is there to abort requests from other threads, and request that aren't completed (no response obtained )

P.S.
Do you set connection limit to ServicePoint that HttpWebRequest uses?
By default the number of connections that can be opened is bound to 2...

you can change that value. The code will look like this
request.ServicePoint.ConnectionLimit = 10

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
thx Vadym...
should i use: request.keepAlive = false when increasing the limit of
servicepoint.connectionLimit...
or maybe i should use asynchronous requests to the url!!!???
 
Hello, (e-mail address removed)!

A> thx Vadym...
A> should i use: request.keepAlive = false when increasing the limit of
A> servicepoint.connectionLimit...
A> or maybe i should use asynchronous requests to the url!!!???

It depends. Here is why.

If you have not too big number of requests to the same internet resource, then setting keep-alive can increase perf. - connections will not be restablished, but kept persistant.

OTOH, if the number of requests is relatively big then keep-alive-ing can decrease performance due to connection limit in ServicePoint...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
I wrote an application like this two years ago to stress test a web
site. Here is my code (c#) -- it is also able to do a form post as
well as url get. It uses WebRequest and uses a Thread array (rather
than Thread pool).

I was able to launch hundreds of threads simultaneously to simulate a
lot of users on web site.

Another thing you could do is implement Tracing in your application, and
put some log entries before the call to the threaded method, and inside
the threaded method before and after the HttpRequest to see where its
getting "stuck".

using System;

using System.Net;
using System.IO;
using System.Text;
using System.Threading;
using System.Web;


namespace crossBow1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///


class Arrow
{

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//

/* if (args.Length < 1) {
showusage();
} else {
if (args.Length < 2 ) {
getPage(args[0], "s1=food&s2=bart");
} else {
getPage(args[0], args[1]);
}
}
*/

// Declare an array of 5 threads to be worker threads.


Thread[] t = new Thread[1000];


for ( int i=0; i< 40 ; i++)
{
t = new Thread(new ThreadStart(quiver));
t.Start();
}

// Console.WriteLine();
// Console.WriteLine("Press any key to continue...");
// Console.ReadLine();

return;


}


public static void quiver()
{

int n = 0;
// string nVs=nameValuePairs();



while(n < 5000)
{
//getPage("http://halppd.vcrm2.com/broadbaseema/www/submitsurvey.jsp",
/*"openfield=five&" +
"SurveyID=0eff76b72e300");*/
//nVs);

//hitPage("http://halagent.vcrm2.com/broadbaseema/ha3094/5dayflash.htm");
//hitPage("http://192.168.25.64/HA3094/5dayflash.htm");
hitPage("http://192.168.25.64/HA3094/blah.html");
n++;
}
}



public static void hitPage(string url)
{
// Initialize the WebRequest.
WebRequest req = WebRequest.Create(url);
req.Timeout = 30000;

try
{
WebResponse result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();

byte[] read = new byte[512];
int bytes = ReceiveStream.Read(read, 0, 512);

string InnerHtml = "";
while (bytes > 0)
{

// Note:
// The following assumes that the response uses UTF-8 as encoding.
// If the content is sent in a ANSI codepage like 932 use something
like this:
// Encoding encode = System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
InnerHtml = InnerHtml + encode.GetString(read, 0, bytes);
bytes = ReceiveStream.Read(read, 0, 512);

}
Console.WriteLine(DateTime.Now + " " + "Success");

}
catch (Exception e)
{
Console.WriteLine(DateTime.Now + " " + "Error retrieving page");
}

}


public static void getPage(String url, String payload)
{
WebResponse result = null;
//Console.WriteLine("payload is " + payload );
try
{

WebRequest req = WebRequest.Create(url);
req.Timeout = 10000;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;

if (payload != null)
{
int i=0, j;
while(i<payload.Length)
{
j=payload.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i,
payload.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, j-i)));

UrlEncoded.Append(payload.Substring(j,1));
i = j+1;
}
SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}


result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader( ReceiveStream, encode );
Console.WriteLine("\r\nResponse stream received");

Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );
Console.WriteLine("HTML...\r\n");
while (count > 0)
{
String str = new String(read, 0, count);
// Console.Write(str);
count = sr.Read(read, 0, 256);
}
}
catch(Exception e)
{
Console.WriteLine( e.ToString());
Console.WriteLine("\r\nThe request URI could not be found or was
malformed");


}
finally
{
if ( result != null )
{
result.Close();
}
}
}



}
}
 
Hello, John!

JAB> I was able to launch hundreds of threads simultaneously to simulate a
JAB> lot of users on web site.

At most 2 connections can be established by default, in order to give more stress to the app being tested it would be better to increase ServicePoint.ConnectionLimit.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
thx alot all of you guys...
i actually increased the servicePoint.connectionLimit of my request and
the program is working fine til now... i'll test it for a couple of
days to be sure that everything is going ok...
thx alot again
best regards
 
Back
Top