6.0.0-beta1
7/4/25

[#4753] Attachment rewrites causing HUGE memory bloat
Summary Attachment rewrites causing HUGE memory bloat
Queue IMP
Queue Version HEAD
Type Bug
State Resolved
Priority 2. Medium
Owners Horde Developers (at) , slusarz (at) horde (dot) org
Requester webadmin (at) ualberta (dot) ca
Created 12/07/2006 (6784 days ago)
Due
Updated 10/04/2007 (6483 days ago)
Assigned 12/14/2006 (6777 days ago)
Resolved 01/20/2007 (6740 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
10/04/2007 04:04:49 PM Chuck Hagenbuch Comment #7 Reply to this comment
I would recommend that you reopen this bug, we experience problems
downloading an 36 mb attachment with a 128 mb memory limit.
With a 256 mb memory limit it is ok.

Running latest stable horde / imp and php.
The changes were made to Horde 3.2/IMP 4.2.
10/04/2007 11:21:36 AM tosca (at) cs (dot) aau (dot) dk Comment #6 Reply to this comment
I would recommend that you reopen this bug, we experience problems

downloading an 36 mb attachment with a 128 mb memory limit.

With a 256 mb memory limit it is ok.



Running latest stable horde / imp and php.



It seems that allot of the memory is consumed by the str_replace calls

in lib/MIME/Contents.php -- One could wonder if a unix/windows line 
shift conversion is really nessecery in a binary attachment, eg. zip 
file. - One might also think it would be smarter streaming the 
attachment directly to the client at download and not drag it through 
php memory?



I haven't looked much into this as other things take priority at the 
moment, does anyone experience similar problems?



Best regards, Martin




01/20/2007 06:39:38 AM Chuck Hagenbuch Comment #5
State ⇒ Resolved
Reply to this comment
Seems to me it's safe to resolve this now.
12/14/2006 09:40:01 PM Chuck Hagenbuch Comment #4
State ⇒ Feedback
Priority ⇒ 2. Medium
Version ⇒ HEAD
Reply to this comment
Moving to HEAD and downgrading a bit since changes have been made, and 
we're waiting to see what happens.
12/08/2006 08:38:09 AM Michael Slusarz Comment #3 Reply to this comment
12/08/2006 08:37:07 AM Michael Slusarz Comment #2
Assigned to Michael Slusarz
Assigned to Horde DevelopersHorde Developers
State ⇒
Reply to this comment
Quite honestly, the best way to tackle this may just be to make this 
change in CVS and play around with it and see what it breaks (if 
anything).  Therefore, all tracking of eol related bugs should occur 
in this ticket.  Also, will get rid of some foreach() calls in favor 
of array_shift() to also help with memory usage.
12/07/2006 09:12:11 PM webadmin (at) ualberta (dot) ca Comment #1
Priority ⇒ 3. High
State ⇒ Unconfirmed
Queue ⇒ IMP
Summary ⇒ Attachment rewrites causing HUGE memory bloat
Type ⇒ Bug
Reply to this comment


We were running into pretty consistent runaway httpd children when 
users would download large (> 30 MB) attachments.  Memory usage would 
balloon to at least 4 times the size of the attachment and the process 
would monopolize the CPU for literally several minutes.  (This was 
after removing or sufficiently increasing various Horde, PHP, and 
system-level limits as the httpd childs would segfault previously.)   
We also found that even moderately sized attachments (>14MB) would 
monopolize the CPU for several minutes and if more than one medium to 
large sized attachments were downloaded at the same time from the same 
server the browser would time out before the download to the client 
even began.



After tracing through way too much PHP, two lines looked suspicious:





--- horde/lib/Horde/MIME/Part.php.bak Wed Jul  5 10:30:47 2006

+++ horde/lib/Horde/MIME/Part.php     Tue Nov 21 03:26:12 2006

@@ -1152 +1152 @@

-            $message = preg_replace("/=\r?\n/", '', $this->_contents);

+//            $message = preg_replace("/=\r?\n/", '', $this->_contents);



--- horde/imp/lib/MIME/Contents.php.bak       Thu May  4 21:30:21 2006

+++ horde/imp/lib/MIME/Contents.php   Tue Nov 21 03:26:26 2006

@@ -173 +173 @@

-            $this->_bodypart[$id] = str_replace("\r\n", "\n", 
$this->_bodypart[$id]);

+//            $this->_bodypart[$id] = str_replace("\r\n", "\n", 
$this->_bodypart[$id]);







These calls were being made for any and all attachments regardless of 
encoding or MIME type.  Completely commenting out both lines 
immediately solved the runaway processes.  A 100 MB JPEG attachment 
took under 10 seconds of processing before download began compared to 
over 10 minutes before (but it still used just over 400 MB of memory).



Where N is the size of the attachment, I'm gonna take a stab in the 
dark and assume the 4N memory requirement is most likely attributed to 
each byte in the attachment being represented as a 32-bit value.  As 
for the CR+LF regexps, I admit I haven't gone through the RFC, but I'm 
guessing this isn't explicitly necessary for the majority of non-text 
attachments especially when they're a base64 blob.  So far, plain 
text, JPEG, TIFF, and random binary blobs have downloaded without 
incident.


Saved Queries