473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

High CPU usage in Sockets

In our application I need to detemine if there is a internet connection
valid.
So I build a windows service which every minute creates telnet connection
against some host and port.
If I do connect to this host I know that internet connection is OK.
The problem: after few days CPU usage growing up to 50% for this service.
After restart it's problem gone for another 2,3 days.

This is a code:
public static bool IsBrowseable(string IP, int Port)

{

bool Result = false;

try

{

IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(IP), Port);

Socket m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);

m_Socket.Connect(localEP);

Result = m_Socket.Connected;

m_Socket.Close();

}

catch (Exception E)

{

Utils.ProcessError("something wrong", E);

Result = false;

}

return Result;

}

Please help to find the problem.

Thanks


Jul 21 '05 #1
6 4779
Sorry, I don't have an answer, but could you please post a follow-up to
this thread if you find one? I am experiencing a similar problem with a
simple sockets application that I wrote. After a few days the CPU usage goes
up to around 50% even though the service isn't really doing anything...

"Anatoly" <an*****@hotmail.com> wrote in message
news:u0**************@tk2msftngp13.phx.gbl...
In our application I need to detemine if there is a internet connection
valid.
So I build a windows service which every minute creates telnet connection
against some host and port.
If I do connect to this host I know that internet connection is OK.
The problem: after few days CPU usage growing up to 50% for this service.
After restart it's problem gone for another 2,3 days.

This is a code:
public static bool IsBrowseable(string IP, int Port)

{

bool Result = false;

try

{

IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(IP), Port);

Socket m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

m_Socket.Connect(localEP);

Result = m_Socket.Connected;

m_Socket.Close();

}

catch (Exception E)

{

Utils.ProcessError("something wrong", E);

Result = false;

}

return Result;

}

Please help to find the problem.

Thanks

Jul 21 '05 #2
I am seeing this behavior in a simple Ping application that we wrote... it
would be wonderful to find a solution.

Brandon

"Anatoly" <an*****@hotmail.com> wrote in message
news:u0**************@tk2msftngp13.phx.gbl...
In our application I need to detemine if there is a internet connection
valid.
So I build a windows service which every minute creates telnet connection
against some host and port.
If I do connect to this host I know that internet connection is OK.
The problem: after few days CPU usage growing up to 50% for this service.
After restart it's problem gone for another 2,3 days.

This is a code:
public static bool IsBrowseable(string IP, int Port)

{

bool Result = false;

try

{

IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(IP), Port);

Socket m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

m_Socket.Connect(localEP);

Result = m_Socket.Connected;

m_Socket.Close();

}

catch (Exception E)

{

Utils.ProcessError("something wrong", E);

Result = false;

}

return Result;

}

Please help to find the problem.

Thanks

Jul 21 '05 #3
I am seeing this behavior in a simple Ping application that we wrote... it
would be wonderful to find a solution.

Brandon


What operating system are you using? I'm running my sockets app on
Win2000. I'm wondering if upgrading to Win2003 would help.
Jul 21 '05 #4
Windows 2003.... sorry. :(

Brandon

"David Sworder" <ds******@cts.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I am seeing this behavior in a simple Ping application that we wrote... it would be wonderful to find a solution.

Brandon


What operating system are you using? I'm running my sockets app on
Win2000. I'm wondering if upgrading to Win2003 would help.

Jul 21 '05 #5
Windows 2003.... sorry. :(

Brandon


Bummer. Have you ever stepped into the code during one of the CPU "fits"
to see what's going on? It's kind of hard for me to do this since the
problem is taking place on a production server. I guess I'm going to have to
start running this app on a development server and step into the code
somehow.
Jul 21 '05 #6
I looked through my sockets code again today. I use the async socket
methods BeginReceive() and EndReceive(). When data is received, EndReceive()
is called, and then BeginReceive() is immediately called in order to
immediately start receiving more data.

One thing I forgot to do is to handle the situation in which
EndReceive() returns zero. This can happen when the client closes his
connection. In my client/server scenario, when a client closes a connection,
EndReceive() on the server typically throws an exception. That's what my
server is designed to handle. It never occurred to me that this method could
return zero until reading the documentation this morning.

I'm wondering if every now and then EndReceive() was returning zero
which then lead to a BeginReceive() call which then lead to another
EndReceive() returning zero, etc... and perhaps this tight loop was causing
the CPU to get hammered. I'm still not sure. This is all speculation at this
point.

I changed my code so that when EndReceive() returns zero, the socket is
closed out (as opposed to calling BeginReceive()). I'll see if this fixes
the problem.

David
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
8
by: Grant Richard | last post by:
Using the TcpListener and TcpClient I created a program that just sends and receives a short string - over and over again. The program is fine until it gets to around 1500 to 1800 messages. At...
6
by: Anatoly | last post by:
In our application I need to detemine if there is a internet connection valid. So I build a windows service which every minute creates telnet connection against some host and port. If I do...
2
by: Cornald Kruyt | last post by:
Hi, I've an database import script written in PHP which used ADO via COM. It makes thousands of queries to a MS-SQL server. The problem is that the process runs out of sockets. The MSSQL...
1
by: Damien | last post by:
Hi guys, I'm looking for ideas for troubleshooting the following. We've tried some random things to try to treat the symptoms, but none seem robust enough to use when we go live, and we'd rather...
2
by: Mechul | last post by:
Hi people i need serious help here.. I have a forum and my hosting company suspended it cuz of the high usage of sql. We did everything to make lower the usage but its still high. it was ...
0
by: Learning.Net | last post by:
I have a window application that uses ActiveX browser component for testing web site automatically using mshtml. Though application is running fine but there is abnormally high page file usage....
1
by: santhescript01 | last post by:
I have a window application that uses ActiveX browser component for testing web site automatically using mshtml. Though application is running fine but there is abnormally high page file usage....
2
by: Sin Jeong-hun | last post by:
In short, is there any way to know the very code that is currently hogging the CPU? I've written an application which continously GETting web pages using HttpWebRequest's asynchronous methods...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.