Open hokkz opened 2 years ago
Thanks for raising this. Yes websocket messages are currently stored in memory, so memory usage will grow over time as websocket messages are received. Calling del driver.requests
will clear them out.
Storing websocket messages in memory was done to ease implementation initially, but we can probably improve on this now. I'll look at making a fix for the next release.
Thank you for your attention. excited to put this issue on the version plan. I tried to use del driver.requests
to clear them, but the result shows that the memory occupation brought by SSL.py
tcp.py
is not released, the following is the console information printing and code
for x in range(0, 20):
print("================================:", datetime.datetime.now())
print(len(driver.requests))
snap = tracemalloc.take_snapshot()
top_stats = snap.statistics('lineno')
for stat in top_stats[:2]:
print(stat)
del driver.requests
time.sleep(3)
================================: 2022-05-26 16:56:05.165671 0 /Users/zonst/2217/py3/lib/python3.8/site-packages/OpenSSL/SSL.py:1769: size=19.2 MiB, count=4888, average=4118 B /Users/zonst/2217/py3/lib/python3.8/site-packages/seleniumwire/thirdparty/mitmproxy/net/tcp.py:145: size=14.1 MiB, count=3587, average=4129 B ================================: 2022-05-26 16:56:08.416115 0 /Users/zonst/2217/py3/lib/python3.8/site-packages/OpenSSL/SSL.py:1769: size=23.0 MiB, count=5863, average=4118 B /Users/zonst/2217/py3/lib/python3.8/site-packages/seleniumwire/thirdparty/mitmproxy/net/tcp.py:145: size=16.9 MiB, count=4305, average=4128 B ================================: 2022-05-26 16:56:11.680175 0 /Users/zonst/2217/py3/lib/python3.8/site-packages/OpenSSL/SSL.py:1769: size=27.1 MiB, count=6891, average=4121 B /Users/zonst/2217/py3/lib/python3.8/site-packages/seleniumwire/thirdparty/mitmproxy/net/tcp.py:145: size=19.8 MiB, count=5041, average=4129 B ================================: 2022-05-26 16:56:14.896431 0 /Users/zonst/2217/py3/lib/python3.8/site-packages/OpenSSL/SSL.py:1769: size=30.8 MiB, count=7840, average=4122 B
Thanks for the additional info.
Aside from the memory usage, is the websocket connection functioning correctly - does the site work as expected? Just trying to establish whether the websocket connection is behaving or in a broken state.
Yes, except that the memory usage continues to grow, the connection of web pages and web sockets is normal
I guess it may not be the problem of selenium-wire, it is the reason why there are live videos in the website I visit, it may be the memory problem of the chrome browser
The problem may lie in mitmproxy which is the engine that Selenium Wire uses internally. I can try to test that by excluding Selenium Wire and using just mitmproxy. Are you able to share the URL?
https://www.tiktok.com/live Try to enter any live room, it is recommended to open multiple live pages at the same time, it is easier to expose the problem
I am not using selenium. When only using the chrome browser to open the page, the problem of continuous increase of memory still exists, so I don't think it is directly related to the related components of webdriver.
I am not using selenium. When only using the chrome browser to open the page, the problem of continuous increase of memory still exists, so I don't think it is directly related to the related components of webdriver.
Sorry for my wrong statement, after I observed it again for a while, I found that the memory usage of chrome will stop increasing after a certain period, but using selenium or selenium-wire memory will increase without an upper limit
were you able to fix this?
The above is the information printing of my console memory usage. This situation will not appear in
selenium
. The following is to open the same environment and web page in selenium