I have a created WCF Service and hosted on my server, my server configuration is:
Processor : Intel Core 2 Duo 2.4 Ghz
RAM : 8 GB
HDD : 300 GB
Visual Studio 2008
There are more than 200 users connecting from remote location to this service through window server and upload file on server. This process is running forever and call this function whenever users have something to send on server.
But at any particular time when all users are connected and uploading the file through this service my w3p process uses high memory and private memory utilization goes to 2.3 GB and more.
Intially my server was having 4 GB of RAM but due to above issue I have to upgrade my RAM to 8 GB because when Private memory utilization goes beyond 2.3 GB my server stop respondings and all other my application on this server hangs up.
Below is my code function of WCF service to uoload file. please help to optimize this and suggest ways by which I can free resources explicitly.
public static void UploadFile(RemoteFileInfo fileRequest, String CreateFilePath)
int chunkSize = 2048;
byte buffer = new byte[chunkSize];
using (System.IO.Stream Stream = new System.IO.MemoryStream
using (System.IO.FileStream writeStream = new System.IO.FileStream (CreateFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
// read bytes from input stream
int bytesRead = Stream.Read(buffer, 0, chunkSize);
if (bytesRead == 0) break;
// write bytes to output stream
writeStream.Write(buffer, 0, bytesRead);
} while (true);