I'm currently writing a web server, but I've noticed as soon as I get a connection the space required by my server increases dramatically, along with its processing time.
When the server starts it uses about 2mb (I get this info from taskmanager), and 0-1% processing time. After a connection (even after one has been handled) its exectution time goes up to about 99% and up to 15mb. Subsequent connections after that dont have any further increase.
When a connection is made, the server makes a call to CreateThread(), which looks like this:
The function started by the thread looks like this:
DWORD dwThreadId; // Info for the thead
// Create a structure of type ARGUMENT to be passed to the new thread
Argument.CLA = ClientAddress;
Argument.SFD = SFD_New;
// CreateThread and process the request
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
ProcessRequest, // thread function
&Argument, // argument to thread function
0, // use default creation flags
); // returns the thread identifier
if (hThread != NULL) // If the thread was created, destroy it
CloseHandle( hThread );
After a connection the server still logs the string "Connection Handled!" (the call to TestLog).
DWORD WINAPI ProcessRequest(LPVOID lpParam )
ARGUMENT * Arg = (ARGUMENT *)lpParam; // Split the paramater into the arguments
CONNECTION * New = new CONNECTION(Arg->SFD, Arg->CLA);
New->ReadRequest(); // Read in the request
New->HandleRequest(); // Handle the request
TestLog("Connection handled!\n"); // Destroy the connection
You'll see that I create a new instance of CONNECTION. I also delete it after the connection has finished processing, and because the Connection Handled string was printed, it should have been deleted.
Is it obvious where I could be having problems? Why does it take up so much processing time all of a sudden? Is there a way in windows of checking how many threads a current application is using? I have a feeling it might be creating threads and not deleting them after perhaps.