-
Notifications
You must be signed in to change notification settings - Fork 152
#223 - SapiStreamEmitter::emit() - high memory usage - memory exhaust #224
#223 - SapiStreamEmitter::emit() - high memory usage - memory exhaust #224
Conversation
Besides CS, this looks good to me! Wondering if there's a way to measure memory peak usage, but I guess there isn't a proper approach... Probably something to be tried with |
I was wondering the same thing about a better way to measure peak memory usage.
I configured the test data to keep memory usage lower (~ 8M x 2) in this particular test. In addition, I made small changes to previous tests to make it easier to find the reason for the test failures (not throwing unecessary exception). |
The test does not work on hhvm. |
…bugs/improvements.
Looking good! Will need to check it out locally and verify it before merging. |
I found another way to track memory usage, I was already using ob_start callback (with small chunck size) to lower memory usage, excluding new output buffer contents (returning null string). Now it also calls the closure that checks the memory consumption. |
I've kept memory track closure apart of output_callback (closure call closure) because of two have different objectives, and the first one can be used in another way (register_tick_function, ob_start, or in read, toString, getContents). |
Linking #223 |
@fcabralpacheco thanks! Merge, added some fixups (only CS), and preparing a release 👍 |
@Ocramius Thanks for CS fixups. I'll try to improve next time. Just one detail, it's missing two returns, after line 66 and 96 of file SapiStreamEmitter.php. The tests were successful because in readable stream they are heavy based on CallbackStream, which detach the callback after a successful call of "getContents" or "__toString", ending in a "eof" condition (maybe I can improve the first tests I wrote to fail if it detects "read" calls in non-readable streams). Also a comment, in "emitBodyRange" may be that someone in the future believes that it is necessary to skip the bytes of the stream until reach first position (in non seekable and readable streams). |
Argh, indeed, I need to adapt the tests. Will revert the patch and check why the tests aren't failing with the missing return statements. |
I think a few |
I think adding more data sets to tests "testEmitBody" and "testEmitBodyRange" with "$expectedReads = 0" and returning false to the method "isReadable" in this situation may be sufficient to detect this kind of problem. |
@Ocramius |
Please check the new PR, I improved the tests a little bit. Thanks. |
No description provided.