Is there a memory leak in the hello world example? #552
Replies: 10 comments
-
@falkoschindler We intend to have this in the #483 as well as the #541. So i appreciate i a lot that you started the analysis. Would you have time for an online session so that we can add this feature to the demo browser together? |
Beta Was this translation helpful? Give feedback.
-
see also https://stackoverflow.com/questions/552744/how-do-i-profile-memory-usage-in-python |
Beta Was this translation helpful? Give feedback.
-
I ran your example on in my environment (Windows) and don't see a problem. The memory stabilizes or goes down after 20 or 30 reloads. The memory may be going up because python is allocating more memory to the dictionaries initially even though the entries into them are not growing. https://lerner.co.il/2019/05/12/python-dicts-and-memory-usage/ By the way, there is MEMORY_DEBUG option that you can set to True in justpy.env that gives you the following printout whenever a websocket disconnects:
It is in the code here: https://github.com/justpy-org/justpy/blob/master/justpy/justpy.py#L177 We may need more elaborate ways to debug memory since it is a crucial issue for scaling. |
Beta Was this translation helpful? Give feedback.
-
@elimintz @WolfgangFahl I can't confirm that the memory stabilizes or goes down. After 300 reloads the number is still growing (at least on my Mac). Sure, Python doesn't allocate new memory for each new dictionary entry, but in chunks. So for a while it might look as if it's not growing anymore. But if you keep reloading, it eventually will.
So even the built-in memory analysis indicates some leakage. |
Beta Was this translation helpful? Give feedback.
-
Ok, will check this more. This is interesting: fastapi/fastapi#4649 |
Beta Was this translation helpful? Give feedback.
-
I upgraded to the latest version of starlette. The problem does not completely go away but the memory leak is more rare. I am using python 3.10 |
Beta Was this translation helpful? Give feedback.
-
@elimintz I can confirm that. Well, if it's a starlette issue, I think we can't do much here. |
Beta Was this translation helpful? Give feedback.
-
I moved it to 0.12 since i consider it important but not urgent and supporting the need for #483. |
Beta Was this translation helpful? Give feedback.
-
I've kept the program running for almost 25 hours now, and it looks like eventually starlette reclaims the memory. Memory usage went down from startup. I think there is no issue here to take care of. |
Beta Was this translation helpful? Give feedback.
-
I modified the Hello World example a tiny bit to track the memory usage.
It looks like there is a leak since the number keeps growing when reloading the page. This already happens with JustPy 0.2.x. Explicitly setting
temp=True
ordelete_flag=True
doesn't help.Weirdly,
jp.WebPage.instances
are not growing. So, what else could hold the page or div objects? Or am I doing something completely wrong measuring the memory?Beta Was this translation helpful? Give feedback.
All reactions