473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4791
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
4111
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
21896
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
291
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
3061
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
4831
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
1590
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
2078
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
2026
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
2320
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
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.