Created
January 7, 2016 00:12
-
-
Save asvetlov/227af16ae9eb38db7f22 to your computer and use it in GitHub Desktop.
aiohttp memleaking test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
from aiohttp import CIMultiDict | |
import tracemalloc | |
def leaking(headers): | |
headers = ''.join(itertools.chain( | |
('status line',), | |
*((k, ': ', v, '\r\n') for k, v in headers.items()))) | |
headers = headers.encode('utf-8') + b'\r\n' | |
return headers | |
def nonleaking(headers): | |
headers = 'status line' + ''.join([ | |
k + ': ' + v + '\r\n' for k, v in headers.items()]) | |
headers = headers.encode('utf-8') + b'\r\n' | |
return headers | |
tracemalloc.start() | |
s0 = tracemalloc.take_snapshot() | |
for i in range(100): | |
for j in range(1000): | |
headers = CIMultiDict({'a': '1', 'b': '2'}) | |
#leaking(headers) | |
nonleaking(headers) | |
s1 = tracemalloc.take_snapshot() | |
diff = s1.compare_to(s0, 'lineno') | |
print("[ Top 10 differences ]") | |
for stat in diff[:10]: | |
p = str(stat) | |
if '/usr/lib' not in p: | |
print(p) | |
s0 = s1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment