Re: listen socket with runloops strange CPU usage
Re: listen socket with runloops strange CPU usage
- Subject: Re: listen socket with runloops strange CPU usage
- From: Mike Miller <email@hidden>
- Date: Sun, 25 Apr 2004 23:41:58 -0700
I don't know a lot about run loop but it makes a little bit of sense. The
main threads run loop is usually never blocked while other threads can spend
the majority of their time blocked. When you put the source in the main loop
I think the effect may be similar to polling the socket for activity hence
the spike in cpu usage. Apples documentation doesn't explictly say not to do
this AFAIK but there are a number of hints that point towards putting this
in a secondary thread. Is the socket performing correctly in both cases?
>
From: Nicolas Berloquin <email@hidden>
>
Date: Sun, 25 Apr 2004 00:27:35 +0200
>
To: email@hidden
>
Subject: listen socket with runloops strange CPU usage
>
>
Hello !
>
>
>
I just noticed something very strange with a listen socket that I
>
create by hand (bind/listen),
>
then transform as a CFSocket with CFSocketCreateWithNative and accept
>
callback events.
>
(All inside a cocoa 10.3.x app).
>
>
>
If I add this CFSocketRef as a runLoopSource in the main runloop with:
>
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSourceRef,
>
kCFRunLoopDefaultMode);
>
CPU usage for my app is around 80-90%, and this during the whole time
>
the app runs.
>
>
I had a separate NSThread already running and I noticed that if I add
>
this CFSocketRef as a runLoopSource
>
to the second thread's runLoop, CPU usage drops down to 2-4%.
>
>
That's a real huge difference. Is this expected behaviour ?
>
>
Things you might like to know:
>
- Same behaviour whether the listen socket is O_NONBLOCK or not.
>
- I also create (a little later on)
>
CFSocketCreateConnectedToSocketSignature() as runloopsources on
>
(either,
>
but always 100%) the main thread or the second thread (same result).
>
- I also tried running my accepted connexions on the main or the second
>
thread (same result).
>
- I have a G4 bipro.
>
>
So my testing on running "everything else" on the second thread or not
>
makes me think that it's not
>
foul play or bad secondary effects inside my code, downward from the
>
socket callback reads etc.
>
>
If this is a bug (apple bug ;-)), maybe this workaround should be
>
advertised ?
>
_______________________________________________
>
macnetworkprog mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.