Socket Performance vs Direct communication

P

pawan

Hi

While performance/stress testing my application (a COM+ Server
component) we drive the transaction to the component via a Socket
Server app, listening to a port and passing the incomming transactions
to the COM+ application. The Socket App then returns the response back
over the opened socket to the client. For a 100 users scenario, 8 CPU
box I am able to get 130 Transactions per seconds.

How ever if I try to pass these transactions directly to an instance of
the COM+ component without the Socket Server, I get performance of 190
Transactions per seconds.

Does spawning a Socket Server really incurr that kind of an overhead,
in this case it is 30%, or I am doing smething wrong with the Socket
Server app. It runs Async and spawns a new thread for each new
connection.

Thanks in Advance
Pawan
 
B

Barry Kelly

pawan said:
Does spawning a Socket Server really incurr that kind of an overhead,
in this case it is 30%, or I am doing smething wrong with the Socket
Server app. It runs Async and spawns a new thread for each new
connection.

I don't understand this bit - one of the main points of using
asynchronous sockets is so that you don't have a new thread for each
connection.

-- Barry
 
P

pawan

Hi Berry

appologies for the confusing statement there. What I meant was that the
Socket Server is running Asynchronously. What is really bugging me is
that the system performance takes a big hit when sending the
transactions thru sockets.

here's what the code looks like:



void CreateServer()
{
int nPort = GetPortNumber();
serverSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint (IPAddress.Any, nPort);
serverSocket.Bind( ipLocal );
serverSocket.Listen(100);
serverSocket.BeginAccept(new AsyncCallback (OnConnectRequest), null);
}

public void OnConnectRequest(IAsyncResult asyncRes)
{
Socket workerSocket = serverSocket.EndAccept (asyncRes);
Interlocked.Increment(ref m_clientCount);
m_workerSocketList.Add(workerSocket);
TransManager txnProcThread = new TransManager(m_clientCount,
fieldDescFilePath, ref htFieldDescList, componentName);
txnProcThread.Init();
htTxnProc.Add(m_clientCount, txnProcThread );
AwaitNOFData(workerSocket, m_clientCount);
ratlServerSocket.BeginAccept(new AsyncCallback ( OnConnectRequest
),null);
}

public void AwaitNOFData(System.Net.Sockets.Socket soc, int
clientNumber)
{
if ( pfnWorkerCallBack == null )
{ pfnWorkerCallBack = new AsyncCallback (ReadNOFData); }
SocketPacket theSocPkt = new SocketPacket (soc, clientNumber);
soc.BeginReceive (theSocPkt.dataBuffer, 0,
theSocPkt.dataBuffer.Length, SocketFlags.None,
pfnWorkerCallBack, theSocPkt);
}



public void ReadNOFData(IAsyncResult asyn)
{
SocketPacket socketData = (SocketPacket)asyn.AsyncState ;
int iRx = socketData.m_currentSocket.EndReceive(asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0);

//Get the input data into string format for invoking PROCESS MESSAGE
string szData = new System.String(chars);
// READ THE INPUT DATA AND INVOKE THE TRANSACTION

try
{
TransManager currentTxn =
(TransManager)htTxnProc[socketData.m_clientNumber];
string returnMsg = currentTxn.DoProcessMsg(szData);
byte[] byData = System.Text.Encoding.ASCII.GetBytes(returnMsg);
Prevresponse = returnMsg.ToString();
Socket workerSocket = (Socket)socketData.m_currentSocket;
workerSocket.Send(byData);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}

// Continue the waiting for data on the Socket
AwaitNOFData(socketData.m_currentSocket, socketData.m_clientNumber );
}


Regards
Pawan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top