fluent-logger-python icon indicating copy to clipboard operation
fluent-logger-python copied to clipboard

using fluent-logger-python with eventlet

Open jshen28 opened this issue 3 years ago • 5 comments

Hello,

I saw a surprising memory usage growth (see this issue). But when I remove monkey_patch looks like memory usage back to normal. Does fluent-logger-python compatible with eventlet?

jshen28 avatar Jan 04 '22 08:01 jshen28

I don't know about eventlet, but I have been using it with gevent in production for about 4 years now with no problems.

arcivanov avatar Jan 04 '22 16:01 arcivanov

I saw fluent-logger uses threading.Local to store last errors, but does it make sense when it is running in an eventlet? I found, although it could be wrong observation, by removing threading.local, memory usage could be surprisingly reduced.

jshen28 avatar Jan 05 '22 00:01 jshen28

The question is how does eventlet monkey-patch the threading.local if at all? You'll also see that we're using threading.Lock. If eventlet is leaking memory through threading.local because it didn't monkey it correctly or if you're leaking eventlets that are not being garbage collected and thus retain local state, then there is not much Fluent logger can do about it, sorry.

arcivanov avatar Jan 05 '22 13:01 arcivanov

I understand, but I am still interested why last_error is stored and how can I take advantage of it. Because I am afraid this may not be easy to solve for eventlet, so if last_error is not used, I am thinking to fork the repo and maintaining a custom version...

jshen28 avatar Jan 06 '22 00:01 jshen28

The reason for a thread local last error is because the same sender is global, can be shared by multiple threads as it's stateless, except for last error. Furthermore, the same behavior in AsyncSender allows the last error to be attributed to the invoking thread. It's not the best design but it's been there for a long time. Judging by eventlet/eventlet#741, it has been confirmed to be an eventlet bug.

I am thinking to fork the repo and maintaining a custom version...

https://www.youtube.com/watch?v=BvK6KsLkPUs

arcivanov avatar Jan 06 '22 03:01 arcivanov