! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Mailwatch uses large amounts of CPU time.
Status:
RESOLVED: FIXED
Severity:
trivial
Product:
Xfce4-mailwatch-plugin
Component:
General

Comments

Description Grant Edwards 2008-10-18 19:50:19 CEST
Created attachment 1903 
Patch to reduce CPU usage due to busy-wait recv() loops.

When the mailwatch process wakes up to poll an IMAP server, it
uses large amounts of CPU for 8-10 seconds.  This is caused by
busy-wait loops that spin calling recv() and gnutls_*_recv()
while waiting for network data.

Attached is a patch that adds a 50ms usleep() to the busy-wait
loops.  This drastically reduces CPU usage.
Comment 1 Brian J. Tarricone (not reading bugmail) 2008-12-04 08:32:45 CET
Thing is, I don't understand why this patch is necessary, and that bothers me.  The socket is set to non-blocking mode, sure.  But the select() call performed before the read() is there to verify that the socket has data ready to be read.  If not, it shouldn't even call read(), and if so, read() should return immediately with data.
Comment 2 Brian J. Tarricone (not reading bugmail) 2008-12-04 08:36:18 CET
Created attachment 2014 
fix select() return code check

Actually, no... the bug is higher up.  The sleeps are unnecessary.  The while() loop for the select() should also continue running if ret == 0, not just (ret < 0 && EINTR == errno).

Does this patch work for you?  Seems to be ok here.
Comment 3 Brian J. Tarricone (not reading bugmail) 2008-12-04 08:36:56 CET
I'm just gonna go ahead and check it in.  Feel free to reopen if it's still broken.
Comment 4 Grant Edwards 2008-12-04 15:40:40 CET
> Thing is, I don't understand why this patch is necessary, and
> that bothers me.

A agree, the sleep() shouldn't be necessary -- it was just an
easy work-around by somebody who 1) has never used gnutls
before and didn't know how the sematics differed from normal
read() calls, and 2) hadn't taken the time to figure out the
looping logic.

I'll give the new code a try sometime in the next week.

Bug #4494

Reported by:
Grant Edwards
Reported on: 2008-10-18
Last modified on: 2011-02-26

People

Assignee:
Brian J. Tarricone (not reading bugmail)
CC List:
1 user

Version

Version:
1.1.0 or older

Attachments

Patch to reduce CPU usage due to busy-wait recv() loops. (1.03 KB, patch)
2008-10-18 19:50 CEST , Grant Edwards
no flags
fix select() return code check (1.05 KB, patch)
2008-12-04 08:36 CET , Brian J. Tarricone (not reading bugmail)
no flags

Additional information