Giter Club home page Giter Club logo

Comments (9)

tonybaloney avatar tonybaloney commented on June 11, 2024 1

thanks for the report. Sorry I haven't replied earlier, I'll repro this and fix the leak. Hopefully its one of the ones we're tackling in #137

from picologging.

JacobCoffee avatar JacobCoffee commented on June 11, 2024

s/Starlite/Litestar 😄

from picologging.

dkull avatar dkull commented on June 11, 2024

Also had a leak with picologging, all is good when swapped back to std logging.
The leak manifested when i passed a logger object deep into threaded + asyncio code. The leak only happened when i called a log function deep down, it didn't leak when the loglevel was higher than the message, or when i didn't call the log function.
Bashed my head against it for a few hours but couldn't crack it, probably leaking fd's and the gc can't collect it or something. Migrating back to std logging for now.

from picologging.

tonybaloney avatar tonybaloney commented on June 11, 2024

For the original sample, I was able to get it running, but I wasn't able to reproduce a memory leak. I wonder if it's the versions that are running? picologging 0.9.2 came with some memory fixes.

To be sure, I've written a minimal sample to use the Litestar queue logger handler (similar to the OP's sample). lite star has changed some of the APIs.

Under Memray for 100,000 HTTP calls, memory usage is stable--

screenshot 2023-09-26 at 10 52 17
from litestar import  Litestar, get, Request
from litestar.logging import LoggingConfig
from litestar.testing import TestClient


logging_config = LoggingConfig(
    loggers={
        "app": {
            "level": "DEBUG",
            "handlers": ["queue_listener"],
            "propagate": False,
        }
    }
)


@get("/")
def hello_world(request: Request) -> dict[str, str]:
    """Handler function that returns a greeting dictionary."""
    request.logger.info("No results in response")
    request.logger.debug("doing things...")
    return {"hello": "world"}


app = Litestar(
    route_handlers=[hello_world],
    logging_config=logging_config,
    debug=True,
)

if __name__ == "__main__":
    with TestClient(app=app) as client:
        for _ in range(100_000):
            response = client.get("/")

@dkull

The leak manifested when i passed a logger object deep into threaded + asyncio code. The leak only happened when i called a log function deep down, it didn't leak when the loglevel was higher than the message, or when i didn't call the log function.

Please could you give me some more detail? I believe everyone, I just can't reproduce a leak to identify where it's coming from.

from picologging.

ThinksFast avatar ThinksFast commented on June 11, 2024

Hey @tonybaloney thanks for looking into this. I'm not 100% certain what version of picologging I was using when I submitted this ticket, but I'm pretty sure it was 0.9.2. I don't think starlite (now called Litestar) had any version constraints on picologging, and I found this in an old requirements.txt file: picologging==0.9.2 for a starlite project I had.

No one else from the litestar project reported this issue with picologging, so there must be something unique about my usage. I was requesting large JSON responses in background tasks... 2-5MB or more, generally. Passing around the data and logging in each function exacerbated the leak.

Are you able to repro with the example I provided? That was made using starlite==1.51.12. You'll have to update the endpoint, it's been migrated since I reported this issue. Try this URL to get large JSON responses: https://fcd.terraclassic.community/v1/staking/validators

Let me know if you have any issues running it.

from picologging.

tonybaloney avatar tonybaloney commented on June 11, 2024

Try updating to 0.9.3, that has a few bug fixes.

Also, there was a memory leak in Litestar/Starlite related to the storage of large responses, but like you pointed out this only occurs when using picologging and not normal logging. Probably worth the update anyway. litestar-org/litestar#1137

from picologging.

ThinksFast avatar ThinksFast commented on June 11, 2024

@tonybaloney I just ran my original script with pico 0.9.3. I didn't have time to set up memray, but looking at activity monitor in macos, you can see memory consumption is pretty high after ~5 minutes of requests.

image

And for comparison, here's memory consumption with regular logging lib... I turned it on, ate dinner and came back after 30 minutes or so.

image

For reference, Starlite normally consumes around 90-125mb of memory at idle.

from picologging.

wreszelewski avatar wreszelewski commented on June 11, 2024

What version of python are you using for tests?
I noticed a leak after switching from python 3.8 to python 3.11. I am using piccologging with other web framework.

from picologging.

ThinksFast avatar ThinksFast commented on June 11, 2024

I've observed the memory leak on 3.10 and 3.11, I haven't tried earlier Python versions

from picologging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.