Hi Guys! If I create a logger with pretty_env_logger, and apply it to create error log once the response code is 500, then my service performance drops from 11.500 req / sec to 8.000 req / sec. Do you have any advice? This is my code
Does your performance only drop that much when all of those requests are internal server errors, or does the performance also drop by just having that condition in your code, even though none of the request actually log anything?
Actually in my test I just have 200OK, and the performance dropped. By for a few hours I have been trying to figure it out, and one silly possibility is my laptop battery power mode. So maybe, its just something different. I need to get a server to test it out. But thank you!
All in all I do not know what is the reason of my performance drop. Now its vary between 6.000-9.000 req per sec. But in the early morning with the same code it was 11.000 req / sec. Soo strange. But I guess its not related to the logging.
I need to check. But without logging and tracing at all, the performance still vary between the same range. And thats really annoying, because yesterday the same wrk test using the same docker containers showed consistently 10.500 req / sec - 11.500 req / sec.
@alice I got something interesting. After my checks I removed completely all the logging codes, even I removed pretty_env_logger and log crated from my Cargo.toml. So removed everything from my code related to logging. And the performance was the same, dropped to ~8.000 req / sec.
And now I did a test. I used the same binary, but I started it with this:
RUST_LOG=trace ./target/release/api
And the performance gained back to 11.000 req / sec. The same code, the same binary, in the binary there is no logging at all, even there is no logging crates - in my code. And somehow this modifies the behavior of the crates related to my project.
Or maybe not... I checked again, and without that trick, now I constant have 11K req/sec performance. The only strange thing, if I run that binary directly from bash, I have 11K req/sec performance, if I put it in a docker container, but using the same port and etc, the same wrk test drops to 8K req/sec. But I saw 11K performance using it in a docker container yesterday. I have no idea whats going on. But 20-25% performance difference should mean something, and Docker should not burn that 20%.
To tell the truth I find it a bit too difficult to follow which number was produced in which scenario. I just wanted to make sure that the drop you see is not related to Docker and the way you're viewing/collecting log messages. We still want to generate as many log messages as we can (trace) while discarding all of them to measure how expensive it is to construct them.
There's definitely a performance hit. Depending on what you need you can try:
use tracing instead of logging and see if its sink implementation performs better than your logging backend
limit tracing to your program, ignoring traces from the dependencies (RUST_LOG=api=trace)
if you're in control of logging, some log messages might be too heavyweight/produce too much data so you can try to limit their size
I'm afraid not. I wouldn't expect the redirection to reduce the performance. Perhaps it's the environment that's changing, background processes, etc. Difficult to say without running multiple tests over longer period of time.