#1484098 closed Bugs (fixed)
Large file attachments consume too much memory when sending messages.
| Reported by: | dopry | Owned by: | |
|---|---|---|---|
| Priority: | 5 | Milestone: | 0.1-rc1 |
| Component: | PHP backend | Version: | 0.1-beta |
| Severity: | major | Keywords: | |
| Cc: |
Description
When sending a file several copies of the attached files are stored as passed around. I believe four copies are being stored in memory. in program/steps/mail/sendmail.inc, 1 copy in $msg_body and 1 copy in MAIL_MIME->_parts (the assign by reference of $msg_body to MAIL_MIME->get has no effect in this case and a copy is created). in program/includes/rcube_sendmail a copied is made when SMTP_CONN->data is called. in program lib/Net/SMTP.php a copied is made by preg_replace for its internal cache.
Two copies of the attached files can be eliminated. 1) unset MIME_MAIL->_parts after msg_body is assigned in program/steps/mail/sendmail.inc. 2) create a $data variable in program/includes/rcube_sendmail and do a call time pass by reference into SMTP_CONN->send, then preg_replace will store a reference. It would be more appropriate to change the function definition of data in Net/SMTP.php to recieve the variable by reference.
These two techniques will save having two copies of the mime attachments in memory, reducing the php memory overhead for attachments to only 2 x total attachment size + ~3 megs. instead of 4x total attachment size + ~3 megs.
Attachments (1)
Change History (3)
Changed 7 years ago by dopry
comment:1 Changed 7 years ago by dopry
- Component changed from Client to PHP backend
- Severity changed from normal to major
Here are some results from my testing before and after the patch... I left the loggin in the patch so you can test for yourself easily.
Message with ~300K attachment, before patch...
[10-Nov-2006 00:18:14] program/steps/sendmail.inc - memory usage(148): 3510832
[10-Nov-2006 00:18:14] program/steps/sendmail.inc - memory usage(148): 3513000
[10-Nov-2006 00:18:14] program/steps/sendmail.inc - memory usage(192): 3513032
[10-Nov-2006 00:18:14] program/steps/sendmail.inc - memory usage(192): 3513272
[10-Nov-2006 00:18:14] program/steps/sendmail.inc - memory usage(222): 4241808
[10-Nov-2006 00:18:14] program/include/rcube_smtp.inc - memory usage(55): 4242624
[10-Nov-2006 00:18:46] program/include/rcube_smtp.inc - memory usage(182): 4273920
[10-Nov-2006 00:18:46] program/lib/Net/SMTP.php - memory usage(766): 4690936
[10-Nov-2006 00:18:46] program/lib/Net/SMTP.php - memory usage(783): 4690936
[10-Nov-2006 00:18:46] program/lib/Net/SMTP.php - memory usage(744): 5107960
300k attachmen after the patch.
[10-Nov-2006 02:45:59] program/steps/sendmail.inc - memory usage(148): 3511224
[10-Nov-2006 02:45:59] program/steps/sendmail.inc - memory usage(200): 3513600
[10-Nov-2006 02:45:59] program/steps/sendmail.inc - memory usage(222): 3932968
[10-Nov-2006 02:45:59] program/include/rcube_smtp.inc - memory usage(55): 3933776
[10-Nov-2006 02:46:22] program/include/rcube_smtp.inc - memory usage(182): 3965328
[10-Nov-2006 02:46:22] program/include/rcube_smtp.inc - memory usage(193): 4382208
[10-Nov-2006 02:46:22] program/lib/Net/SMTP.php - memory usage(766): 4381896
[10-Nov-2006 02:46:22] program/lib/Net/SMTP.php - memory usage(783): 4381896
[10-Nov-2006 02:46:22] program/lib/Net/SMTP.php - memory usage(744): 4381896
[10-Nov-2006 02:46:22] program/lib/Net/SMTP.php - memory usage(756): 4387320
[10-Nov-2006 02:46:22] program/lib/Net/SMTP.php - memory usage(783): 4387400
cheers. -dopry
comment:2 Changed 6 years ago by thomasb
- Milestone set to 0.1-rc1
- Resolution set to fixed
- Status changed from new to closed
Added patch to Trunk ([b517af4a])

patch to save creating two unneccesary copies of mime_attachments in memory.