-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FPM logger refactoring #2458
FPM logger refactoring #2458
Conversation
We are heavily facing this issue and would be more than happy if this could make it into a PHP release quite fast! :-) |
Totally the same here |
I'm afraid it will have to wait officially till 7.3 as there is still quite a lot of work to do and my time quite limited considering that I also need to couple of things in json and openssl ext before the 7.2 deadline that is very close. However I'm thinking about creating a separate SAPI that I would maintain separately and it would work with 7.0+. As I said it still needs quite a lot of work as there quite a few issues and needs some extended testing. I will prioritise it after the first beta for 7.2. |
This addition would be awseome! I'm currently patching the hardcoded limit value everytime a new release is built :) |
Just to give an update. I'm slowly working on it as part of FPMi |
This would be a huge advantage for the community running php in docker where there is a convention to log everything to SDTOUT so that log aggregation can have a common solution for all containers, not on a app-by-app basis. It's a big problem at the moment that app logs have the above mentioned prefix and warning. It would be a huge WIN to be able to remove it (or customise it). |
@bukka this is definitely hero's work, appreciate your take on this. Is there any way we can help you on this? |
@ingluisjimenez thanks for offering the help. I will send an update once I'm happy with the patch and then it would be really great if you and possibly others could test it! In the meantime the progress (currently I'm a bit slow but hope to have more time soon) can be seen here: bukka/fpmi@0.1.0...next |
Thanks for your recent work on this, @bukka. Can I help test anything, discuss anything, verify anything, give feedback on current state? |
@dzuelke Thanks! I think I have got most of the functionality in there (currently just in fpmi as linked above) but it needs some optimization for buffered logging - mainly reusing buffer. Also need to do a little bit more testing on my side but hopefully won't take too much time. Once it's done it would be great if you and others could test it. I will send a bit more detailed description of what has been done. |
No problem @bukka, I can set aside work time to assist with testing etc. Just ping me when! |
53b0e28
to
30f5ff0
Compare
@dzuelke , @ingluisjimenez and others: I think it's ready for testing. There are 3 new options:
A little more info about the options can be seen in the updated conf files. |
sapi/fpm/php-fpm.conf.in
Outdated
; logging to a file descriptor. It means the new line character is not present | ||
; when logging to syslog. | ||
; Default Value: 1024 | ||
;log_level = 4096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this say log_limit
instead of log_level
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch! Will fix it! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now!
Is there any reason |
Could you also describe the idea behind |
I have been thinking about it but if buffering is used (which is default and primary mode), buffer is reused so it is kept in the memory and it could result in a really big buffer. It's kind of like zones in nginx (with an exception that it's not a shared memory [just master allocated memory] and it's the maximum that it can grow to) - you don't create an unlimited zone. If you want to allow really long lines (note that this is a limit for a single line), then you can set it high but there should be always some reasonable limit IMHO.
If it's on (default), then it's a buffering for a single line. Basically the line is then written in a single write call. |
I wonder if disabling that is useful in any way. Presumably a program could e.g. IMO writes should purely line based, and atomic (in one call). For logging to stdout/stderr that are not CLI apps (think |
@bukka Just to check, does the merged version fix the "pipe is closed" issue from above? Or is that supposed to work that way? |
@dzuelke Ok I merged it as it's already in much better state than the current logging but will take a look on that issue with a high log limit during the beta. About the default change, I'm not really sure as it can technically break some old syslog loggers - not sure however how likely it is. I will keep it for now... That leak looks strange as it is in filter extension so not really sure if it's even related as these are changes mainly for master process... If you can take a look, that would be great! |
@nikic What "pipe is closed" issue? :) If you mean the line split, that was already present and never worked properly. The only issue that I know about is the one with very large log limit that I plan to take a look during the beta. I don't think it will require complex changes - the hardest part will be to debug it... |
Not the line split, @bukka, but note how every single |
@dzuelke I think it says that either the read failed for some unusual reason (which is also logged as SYSERROR) or the pipe was closed during the processing so it means that the logged message is incomplete. I guess it might be useful to know if the logged message is just partial but not 100% sure. |
I have got an initial fix in fpmi: bukka/fpmi@912c9f0 . I plan to push it to fpm but would like to actually cover the closed pipe branch in test. Not really sure how to recreate it atm. I can get the pipe fd (at least I think that's the fd) like:
but not really sure how to close it without re-opening. Something like |
But what's the closed pipe branch even for? When does that happen? If a message arrives, but between receiving it and emitting it, the pipe has closed? Doesn't the closing only happen if that child shuts down? The question for me remains: in what way is the " Why not just remove that whole bit? |
@dzuelke I guess it's more an info that the log message is not complete so you know that not everything has been logged. It could also happen if pipe I have fixed it in 2a67d62 as well as did a bit of reordering so the unlikely sys error is after the message. I think that should do. |
@dzuelke I just tried to recreate your issue with long limit but no success. This is my config and steps that I used:
Could you provide your config and steps that show the issue so I can recreate it? |
@dzuelke I just closed https://bugs.php.net/bug.php?id=69031 . If you manage to recreate the issue above, please open a new bug and ping me in here... |
Still happening with beta2, @bukka, yup. Even occasionally with 16384:
Config:
|
@dzuelke I'm not really able to recreate it but I think it might be because the message was split to multiple events in your environment. Also as discussed before, it's not ideal that the message is ended at the end of the event instead of the request. So I implemented storing the log stream in the child and it's now merged: Please let me know if you can still see the issue. You can either build the latest 7.3 branch or it should be available in the next beta. |
@dzuelke Btw. the change mentioned in the previous comment is a relatively bigger one so if you manage to test more cases like before, that would be really appreciated! Thanks! |
@dzuelke Sorry for the late replay. Nothing specific but was thinking more about some kind of regression testing that you did initially. Ideally testing mainly the buffering on as it will be the default - (off is more experimental) with checking if decoration on/off and different limits work correctly. It would be also great to keep an eye on memory usage (possibly also run it under valgrind) and see if there are any changes in perf compare to 7.2 (there shouldn't be but just in case there is some regression). If anyone else is also interested doing some fpm log testing with latest 7.3 rc, that would be highly appreciated! Thanks! |
As of PHP 7.3 we finally use STDOUT and STDERR properly in our containers, this disables the '[pool %s] child %d said into %s: \"%s\' format. More info: - php/php-src#2458 - https://bugs.php.net/bug.php?id=71880 - docker-library#207
…derr) It has been fixed in PHP 7.3: php/php-src#2458 With a custom php-fpm parameter: `decorate_workers_output`
Not sure if this is related, because long log messages work, just not all the time: https://serverfault.com/q/1017932/403177 |
As of PHP 7.3 we finally use STDOUT and STDERR properly in our containers, this disables the '[pool %s] child %d said into %s: \"%s\' format. More info: - php/php-src#2458 - https://bugs.php.net/bug.php?id=71880 - docker-library/php#207
As of PHP 7.3 we finally use STDOUT and STDERR properly in our containers, this disables the '[pool %s] child %d said into %s: \"%s\' format. More info: - php/php-src#2458 - https://bugs.php.net/bug.php?id=71880 - docker-library/php#207
As of PHP 7.3 we finally use STDOUT and STDERR properly in our containers, this disables the '[pool %s] child %d said into %s: \"%s\' format. More info: - php/php-src#2458 - https://bugs.php.net/bug.php?id=71880 - docker-library/php#207
This is just an initial work on the log limit for FPM (just a zlog part). It introduces a new global conf
log_limit
that defaults to previous value 1024. Currently this is meant mainly forerror_log
function and removing truncating of child pipes from stdio whencatch_workers_output
is enabled (the...
). However that part is still wrapped and I think we should have an another config for that as it's not log related exactly. I actually created an empty API in zlog to address that and it's calledzlog_stream
which will allow push based approach. The thing is that zlog just adds a prefix and then pass it to the zlog_fd (unless it is set for syslog which still requires buffering). If zlog_fd is a normal stream, then we should be able to just pass it without extra copying (it means doing multiple writes). The situation gets slightly more complicated with children (workers) which is for example used when you doerror_log
. They do also external logging using fcgi_write insapi_cgi_log_fastcgi
but it could be also optimised to not do extra copying.So from the above it is clear that there is a huge space for improvements and optimization and the patch will be probably considerably changed before I remove the WIP from title and make it ready for review (btw. it's still probably buggy so don't use it anywhere yet :) ).
I'm opening this PR to mainly see what others think about
log_limit
setting and also about another option calledworker_output_limit
that I'm preparing for the piped variant (the one used whencatch_workers_output
set). That would basically extend the size of the wrapping. I was also thinking about another option that would allow to remove prefix[pool %s] child %d said into %s: \"%s\
, ugly double quoting and maybe even the warning prefix but not sure atm. I will be glad to hear your thoughts about that! :)Also this is an initial answer to #1076 . Atm. it's based on master
7.1but the final branch will depend how much refactoring I will do, how much confident I will be with the changes and of course on the RM. If it gets too big I will probably rebase it to master...