Solved

why  the cpu usage goes to 100% when the the idtcpclient connects to idtcpserver

Posted on 2007-11-18
4
862 Views
Last Modified: 2012-05-05
I did a simple program that connects a component tidtcpclient to tidtcpserver, but when it connects the server, on the server side the cpu usage goes to 100%, and stay on it, so why this happaning? and this is normal? i only connected, that's it.
0
Comment
Question by:rafaelrgl
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
ciuly earned 300 total points
ID: 20309173
I think I know what the problem is. you are not using the servers onexecute event, or are using it incorrectly.

all processing must be done in the server onexecute event using the parameter which identifies the thread (from which you get the connection object). that event is beeing executed in the context of that specific thread, so keep in mind that you will have to synchronize access to any shared resources.

if you don't want to use that event (I've had such an application myself where I just notified another thread of the existing data and the server processed it whenever it got time), you simply assign the event and in it you doo a sleep(5); (very small value).
this will make sure that :
- your server's client thread doesn't get blocked for too much time
- AND, the cpu is not used extensivly.

because what happens is that as long as there is some data to be read from the client end, the server will keep executing that event. so if you don't process data in it, it will be executed in a loop very fast ;)
0
 
LVL 17

Assisted Solution

by:TheRealLoki
TheRealLoki earned 100 total points
ID: 20309375
can you show us your server's code please.
I think Ciuly is right, you are probably using the OnConnect event instead of the OnExecute event.
0
 
LVL 19

Assisted Solution

by:MerijnB
MerijnB earned 100 total points
ID: 20311270
alternatively, if you are not familiar with sync programming, use something like ICS (free): http://www.overbyte.be/frame_index.html?redirTo=/products/ics.html
0
 
LVL 28

Expert Comment

by:ciuly
ID: 20311348
(this is an addition/extension to merijnb's post)

it's not really sycn programming. indy uses blocking (synchronous) sockets whereas ics uses non-blocking (asyncronous) sockets. so it's not the programming style but the socket type. and in both cases, the basic style is to use events, the difference is the way those events are fired and processed. and of course that the socket type induces a certain programming style, but I for example have made 2 systems until today that can use blocking sockets in a non-blocking fashion. of course, the unrelying atomic data is a (n xml) command so the event is fired when such a command is available to be processed.
what I want to say is that no matter of the socket type you can use any programming style, but you'll just have to be carefull :)

basically, both types of sockets are best fit for specific types of applications (complementary). and as I said above, both types of sockets can be used in the other types of applications where they don't fit so well.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now