Resource consuming. 
Author Message
 Resource consuming.

Hi,

 I've got a little application which uses sockets to connect to some other
applications and retrieve data from them.The problem is that this
application consumes practically all the processor's time when I execute it.
I've been optimizing loops but the problem is still there. My question is if
it could be possible that the use of sockets could be affeting the
performance of the code.

Regards,

--
Juan A. Rosell Ortega
Meteor Data Communication NV
Kerkenbos 10-47
6546 BB  Nijmegen
The Nederlands

Tel: +31-243717575
Direct: +31-24 3717579
Fax: +31-24 3791179



Mon, 30 Jun 2003 18:05:23 GMT  
 Resource consuming.
Sounds like a while(1) loop in your code.
Share some part?

Cheers,
Guillaume.



Quote:

> Hi,

>  I've got a little application which uses sockets to connect to some other
> applications and retrieve data from them.The problem is that this
> application consumes practically all the processor's time when I execute
it.
> I've been optimizing loops but the problem is still there. My question is
if
> it could be possible that the use of sockets could be affeting the
> performance of the code.

> Regards,

> --
> Juan A. Rosell Ortega
> Meteor Data Communication NV
> Kerkenbos 10-47
> 6546 BB  Nijmegen
> The Nederlands

> Tel: +31-243717575
> Direct: +31-24 3717579
> Fax: +31-24 3791179



Mon, 30 Jun 2003 18:32:15 GMT  
 Resource consuming.

 No, there's no while(1) loop, there's only a main loop that waits until a
flag changes from 'false' to 'true' to finish.


Quote:
> Sounds like a while(1) loop in your code.
> Share some part?

> Cheers,
> Guillaume.



> > Hi,

> >  I've got a little application which uses sockets to connect to some
other
> > applications and retrieve data from them.The problem is that this
> > application consumes practically all the processor's time when I execute
> it.
> > I've been optimizing loops but the problem is still there. My question
is
> if
> > it could be possible that the use of sockets could be affeting the
> > performance of the code.

> > Regards,

> > --
> > Juan A. Rosell Ortega
> > Meteor Data Communication NV
> > Kerkenbos 10-47
> > 6546 BB  Nijmegen
> > The Nederlands

> > Tel: +31-243717575
> > Direct: +31-24 3717579
> > Fax: +31-24 3791179



Mon, 30 Jun 2003 18:50:44 GMT  
 Resource consuming.
So that's your faulty loop!!!
Try to add a Sleep in your loop to avoid puping CPU time.
You can also use an event and WaitForSingleObject().
If you could share this loop (or a pseudo code of it) we could have a better
view how to solve this.

Cheers,
Guillaume.



Quote:

>  No, there's no while(1) loop, there's only a main loop that waits until a
> flag changes from 'false' to 'true' to finish.



> > Sounds like a while(1) loop in your code.
> > Share some part?

> > Cheers,
> > Guillaume.



> > > Hi,

> > >  I've got a little application which uses sockets to connect to some
> other
> > > applications and retrieve data from them.The problem is that this
> > > application consumes practically all the processor's time when I
execute
> > it.
> > > I've been optimizing loops but the problem is still there. My question
> is
> > if
> > > it could be possible that the use of sockets could be affeting the
> > > performance of the code.

> > > Regards,

> > > --
> > > Juan A. Rosell Ortega
> > > Meteor Data Communication NV
> > > Kerkenbos 10-47
> > > 6546 BB  Nijmegen
> > > The Nederlands

> > > Tel: +31-243717575
> > > Direct: +31-24 3717579
> > > Fax: +31-24 3791179



Mon, 30 Jun 2003 20:04:45 GMT  
 Resource consuming.

I've already put a Sleep(0) at the end of the loop, but it keeps on
behaiving the same way. Here you are
the loop in pseudocode:

  while(!done){

     if (kbhit()){
       GetChar();
       switch (connexion):
          SERIAL:  write_serial_connection();
          SOCKET:send_char();
       }
     }
     else{
       switch (connexion):
          SERIAL:  read_serial_connection();
          SOCKET: receive_char();
       }
     }
     Sleep(0);
   }

 This is the main loop.

 Regards,

Juan A. Rosell Ortega
Meteor Data Communication NV
Kerkenbos 10-47
6546 BB  Nijmegen
The Nederlands

Tel:     +31-24 3717575
Direct: +31-24 3717579
Fax:     +31-24 3791179


Quote:
> So that's your faulty loop!!!
> Try to add a Sleep in your loop to avoid puping CPU time.
> You can also use an event and WaitForSingleObject().
> If you could share this loop (or a pseudo code of it) we could have a
better
> view how to solve this.

> Cheers,
> Guillaume.

> > > > --
> > > > Juan A. Rosell Ortega
> > > > Meteor Data Communication NV
> > > > Kerkenbos 10-47
> > > > 6546 BB  Nijmegen
> > > > The Nederlands

> > > > Tel: +31-243717575
> > > > Direct: +31-24 3717579
> > > > Fax: +31-24 3791179



Tue, 01 Jul 2003 23:12:54 GMT  
 Resource consuming.
Also you might consider looking at MsgWaitForMultipleObjects too, if you can
set up your socket / serial read as an overlapped operation. Or move
blocking operations onto a worker thread so it doesn't clog your main
operation. This is assuming you're writing something that doesn't have to be
portable - the kbhit() loop is a bit of a holdover from DOS style
programming.

David


Quote:
> Sleep(0) doesn't stop you from using all CPU time. Sleep(0)
> means sleep for zero milliseconds. Sleep(0) may make your
> application share the CPU better with other needy programs,
> but that is very operating system and priority dependent. I
> strongly recommend avoiding Sleep(0).

> Change it to Sleep(1), or else use functions that wait for
> events to happen.

> Polling tends to use 100% of the CPU time, unless you put
> in short waits (Sleep(1)). You shouldn't be surprised at
> the behaviour.


> > I've already put a Sleep(0) at the end of the loop, but it keeps on
> > behaiving the same way. Here you are
> > the loop in pseudocode:

> >   while(!done){

> >      if (kbhit()){
> >        GetChar();
> >        switch (connexion):
> >           SERIAL:  write_serial_connection();
> >           SOCKET:send_char();
> >        }
> >      }
> >      else{
> >        switch (connexion):
> >           SERIAL:  read_serial_connection();
> >           SOCKET: receive_char();
> >        }
> >      }
> >      Sleep(0);
> >    }

> >  This is the main loop.

> >  Regards,

> > Juan A. Rosell Ortega
> > Meteor Data Communication NV
> > Kerkenbos 10-47
> > 6546 BB  Nijmegen
> > The Nederlands

> > Tel:     +31-24 3717575
> > Direct: +31-24 3717579
> > Fax:     +31-24 3791179



> > > So that's your faulty loop!!!
> > > Try to add a Sleep in your loop to avoid puping CPU time.
> > > You can also use an event and WaitForSingleObject().
> > > If you could share this loop (or a pseudo code of it) we could have a
> > better
> > > view how to solve this.

> > > Cheers,
> > > Guillaume.

> > > > > > --
> > > > > > Juan A. Rosell Ortega
> > > > > > Meteor Data Communication NV
> > > > > > Kerkenbos 10-47
> > > > > > 6546 BB  Nijmegen
> > > > > > The Nederlands

> > > > > > Tel: +31-243717575
> > > > > > Direct: +31-24 3717579
> > > > > > Fax: +31-24 3791179

> --
> .Bruce Dawson, Humongous Entertainment (we're hiring).
> http://www.humongous.com/
> Send job applications by e-mail, post technical questions
> to the newsgroups please. Thanks.



Wed, 02 Jul 2003 02:00:18 GMT  
 Resource consuming.
Sleep(0) doesn't stop you from using all CPU time. Sleep(0)
means sleep for zero milliseconds. Sleep(0) may make your
application share the CPU better with other needy programs,
but that is very operating system and priority dependent. I
strongly recommend avoiding Sleep(0).

Change it to Sleep(1), or else use functions that wait for
events to happen.

Polling tends to use 100% of the CPU time, unless you put
in short waits (Sleep(1)). You shouldn't be surprised at
the behaviour.

Quote:

> I've already put a Sleep(0) at the end of the loop, but it keeps on
> behaiving the same way. Here you are
> the loop in pseudocode:

>   while(!done){

>      if (kbhit()){
>        GetChar();
>        switch (connexion):
>           SERIAL:  write_serial_connection();
>           SOCKET:send_char();
>        }
>      }
>      else{
>        switch (connexion):
>           SERIAL:  read_serial_connection();
>           SOCKET: receive_char();
>        }
>      }
>      Sleep(0);
>    }

>  This is the main loop.

>  Regards,

> Juan A. Rosell Ortega
> Meteor Data Communication NV
> Kerkenbos 10-47
> 6546 BB  Nijmegen
> The Nederlands

> Tel:     +31-24 3717575
> Direct: +31-24 3717579
> Fax:     +31-24 3791179



> > So that's your faulty loop!!!
> > Try to add a Sleep in your loop to avoid puping CPU time.
> > You can also use an event and WaitForSingleObject().
> > If you could share this loop (or a pseudo code of it) we could have a
> better
> > view how to solve this.

> > Cheers,
> > Guillaume.

> > > > > --
> > > > > Juan A. Rosell Ortega
> > > > > Meteor Data Communication NV
> > > > > Kerkenbos 10-47
> > > > > 6546 BB  Nijmegen
> > > > > The Nederlands

> > > > > Tel: +31-243717575
> > > > > Direct: +31-24 3717579
> > > > > Fax: +31-24 3791179

--
.Bruce Dawson, Humongous Entertainment (we're hiring).
http://www.humongous.com/
Send job applications by e-mail, post technical questions
to the newsgroups please. Thanks.


Wed, 02 Jul 2003 01:18:15 GMT  
 Resource consuming.

Thanks to all of you, at least my problem was the blocking operations in the
sockets.

 Juan


Quote:
> Also you might consider looking at MsgWaitForMultipleObjects too, if you
can
> set up your socket / serial read as an overlapped operation. Or move
> blocking operations onto a worker thread so it doesn't clog your main
> operation. This is assuming you're writing something that doesn't have to
be
> portable - the kbhit() loop is a bit of a holdover from DOS style
> programming.

> David



> > Sleep(0) doesn't stop you from using all CPU time. Sleep(0)
> > means sleep for zero milliseconds. Sleep(0) may make your
> > application share the CPU better with other needy programs,
> > but that is very operating system and priority dependent. I
> > strongly recommend avoiding Sleep(0).

> > Change it to Sleep(1), or else use functions that wait for
> > events to happen.

> > Polling tends to use 100% of the CPU time, unless you put
> > in short waits (Sleep(1)). You shouldn't be surprised at
> > the behaviour.


> > > I've already put a Sleep(0) at the end of the loop, but it keeps on
> > > behaiving the same way. Here you are
> > > the loop in pseudocode:

> > >   while(!done){

> > >      if (kbhit()){
> > >        GetChar();
> > >        switch (connexion):
> > >           SERIAL:  write_serial_connection();
> > >           SOCKET:send_char();
> > >        }
> > >      }
> > >      else{
> > >        switch (connexion):
> > >           SERIAL:  read_serial_connection();
> > >           SOCKET: receive_char();
> > >        }
> > >      }
> > >      Sleep(0);
> > >    }

> > >  This is the main loop.

> > >  Regards,

> > > Juan A. Rosell Ortega
> > > Meteor Data Communication NV
> > > Kerkenbos 10-47
> > > 6546 BB  Nijmegen
> > > The Nederlands

> > > Tel:     +31-24 3717575
> > > Direct: +31-24 3717579
> > > Fax:     +31-24 3791179



> > > > So that's your faulty loop!!!
> > > > Try to add a Sleep in your loop to avoid puping CPU time.
> > > > You can also use an event and WaitForSingleObject().
> > > > If you could share this loop (or a pseudo code of it) we could have
a
> > > better
> > > > view how to solve this.

> > > > Cheers,
> > > > Guillaume.

> > > > > > > --
> > > > > > > Juan A. Rosell Ortega
> > > > > > > Meteor Data Communication NV
> > > > > > > Kerkenbos 10-47
> > > > > > > 6546 BB  Nijmegen
> > > > > > > The Nederlands

> > > > > > > Tel: +31-243717575
> > > > > > > Direct: +31-24 3717579
> > > > > > > Fax: +31-24 3791179

> > --
> > .Bruce Dawson, Humongous Entertainment (we're hiring).
> > http://www.humongous.com/
> > Send job applications by e-mail, post technical questions
> > to the newsgroups please. Thanks.



Fri, 04 Jul 2003 16:26:11 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. How to find out amount of free resources (gdi resources, handles, system resources)

2. KeyDown consuming anomalies ?

3. How to consume base64Binary xml using C++ ?

4. Consuming WebServices

5. Struct can't consume event problem

6. ERROR Consuming ATL Web Services in C#.Net..

7. Consuming WSDL on the client

8. CPU/time Consuming Operations?

9. ERROR Consuming ATL Web Services in C#.Net..

10. ActiveX Control consuming a .NET (C#) webservice

11. How to interrupt a time consuming activity.

12. Time Consumed by Child Processes

 

 
Powered by phpBB® Forum Software