{"action":"opened","number":2262,"pull_request":{"url":"https://api.github.com/repos/ckan/ckan/pulls/2262","id":28633529,"html_url":"https://github.com/ckan/ckan/pull/2262","diff_url":"https://github.com/ckan/ckan/pull/2262.diff","patch_url":"https://github.com/ckan/ckan/pull/2262.patch","issue_url":"https://api.github.com/repos/ckan/ckan/issues/2262","number":2262,"state":"open","locked":false,"title":"[#1847] Add middleware that cleans up the pylons response string.","user":{"login":"joetsoi","id":241130,"avatar_url":"https://avatars.githubusercontent.com/u/241130?v=3","gravatar_id":"","url":"https://api.github.com/users/joetsoi","html_url":"https://github.com/joetsoi","followers_url":"https://api.github.com/users/joetsoi/followers","following_url":"https://api.github.com/users/joetsoi/following{/other_user}","gists_url":"https://api.github.com/users/joetsoi/gists{/gist_id}","starred_url":"https://api.github.com/users/joetsoi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joetsoi/subscriptions","organizations_url":"https://api.github.com/users/joetsoi/orgs","repos_url":"https://api.github.com/users/joetsoi/repos","events_url":"https://api.github.com/users/joetsoi/events{/privacy}","received_events_url":"https://api.github.com/users/joetsoi/received_events","type":"User","site_admin":false},"body":"Once the response string has been served, this middleware replaces the response string with a dummy one, so the original response can be garbage collected. This is lifted from https://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode This middleware is can be switched on by setting 'ckan.use_pylons_response_cleanup_middleware = true' in your development.ini\r\n\r\nSo I did a comparison of with and without this enabled. Everyone likes graphs right?\r\n![memory_usage](https://cloud.githubusercontent.com/assets/241130/6040058/6ddc56a8-ac65-11e4-98f1-01fb1703df38.png)\r\nNotably, the memory usage still grows with this enabled, but is a bit more stable. I also did some examining of the memory and this memory has been returned to python's free lists but has not been released by the python process. see (http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm). So use up as much memory as there are threads\r\n\r\nSo the other way around it is to do something like use gunicorn +  gevent, although this isn't a fair direct comparison as this is only using one worker process, but I mainly suggest this as you can set worker processes to restart after serving a maximum number of requests (see http://docs.gunicorn.org/en/develop/configure.html#max-requests), which would release any memory that the process has been allocated but is not using.\r\n\r\nAnyway, this isn't critical or anything as it does just 'fix' an edge case that most people will not come across. (still needs tests)\r\n","created_at":"2015-02-04T12:08:46Z","updated_at":"2015-02-04T12:08:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ckan/ckan/pulls/2262/commits","review_comments_url":"https://api.github.com/repos/ckan/ckan/pulls/2262/comments","review_comment_url":"https://api.github.com/repos/ckan/ckan/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ckan/ckan/issues/2262/comments","statuses_url":"https://api.github.com/repos/ckan/ckan/statuses/211cd50830a2e2c7c36de36ce708b0bd5166f44e","head":{"label":"joetsoi:1847-pylons-clean-middleware","ref":"1847-pylons-clean-middleware","sha":"211cd50830a2e2c7c36de36ce708b0bd5166f44e","user":{"login":"joetsoi","id":241130,"avatar_url":"https://avatars.githubusercontent.com/u/241130?v=3","gravatar_id":"","url":"https://api.github.com/users/joetsoi","html_url":"https://github.com/joetsoi","followers_url":"https://api.github.com/users/joetsoi/followers","following_url":"https://api.github.com/users/joetsoi/following{/other_user}","gists_url":"https://api.github.com/users/joetsoi/gists{/gist_id}","starred_url":"https://api.github.com/users/joetsoi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joetsoi/subscriptions","organizations_url":"https://api.github.com/users/joetsoi/orgs","repos_url":"https://api.github.com/users/joetsoi/repos","events_url":"https://api.github.com/users/joetsoi/events{/privacy}","received_events_url":"https://api.github.com/users/joetsoi/received_events","type":"User","site_admin":false},"repo":{"id":19034370,"name":"ckan","full_name":"joetsoi/ckan","owner":{"login":"joetsoi","id":241130,"avatar_url":"https://avatars.githubusercontent.com/u/241130?v=3","gravatar_id":"","url":"https://api.github.com/users/joetsoi","html_url":"https://github.com/joetsoi","followers_url":"https://api.github.com/users/joetsoi/followers","following_url":"https://api.github.com/users/joetsoi/following{/other_user}","gists_url":"https://api.github.com/users/joetsoi/gists{/gist_id}","starred_url":"https://api.github.com/users/joetsoi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joetsoi/subscriptions","organizations_url":"https://api.github.com/users/joetsoi/orgs","repos_url":"https://api.github.com/users/joetsoi/repos","events_url":"https://api.github.com/users/joetsoi/events{/privacy}","received_events_url":"https://api.github.com/users/joetsoi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/joetsoi/ckan","description":"CKAN is an open-source DMS (data management system) for powering data hubs and data portals. CKAN makes it easy to publish, share and use data. It powers datahub.io, catalog.data.gov and data.gov.uk among many other sites.","fork":true,"url":"https://api.github.com/repos/joetsoi/ckan","forks_url":"https://api.github.com/repos/joetsoi/ckan/forks","keys_url":"https://api.github.com/repos/joetsoi/ckan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/joetsoi/ckan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/joetsoi/ckan/teams","hooks_url":"https://api.github.com/repos/joetsoi/ckan/hooks","issue_events_url":"https://api.github.com/repos/joetsoi/ckan/issues/events{/number}","events_url":"https://api.github.com/repos/joetsoi/ckan/events","assignees_url":"https://api.github.com/repos/joetsoi/ckan/assignees{/user}","branches_url":"https://api.github.com/repos/joetsoi/ckan/branches{/branch}","tags_url":"https://api.github.com/repos/joetsoi/ckan/tags","blobs_url":"https://api.github.com/repos/joetsoi/ckan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/joetsoi/ckan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/joetsoi/ckan/git/refs{/sha}","trees_url":"https://api.github.com/repos/joetsoi/ckan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/joetsoi/ckan/statuses/{sha}","languages_url":"https://api.github.com/repos/joetsoi/ckan/languages","stargazers_url":"https://api.github.com/repos/joetsoi/ckan/stargazers","contributors_url":"https://api.github.com/repos/joetsoi/ckan/contributors","subscribers_url":"https://api.github.com/repos/joetsoi/ckan/subscribers","subscription_url":"https://api.github.com/repos/joetsoi/ckan/subscription","commits_url":"https://api.github.com/repos/joetsoi/ckan/commits{/sha}","git_commits_url":"https://api.github.com/repos/joetsoi/ckan/git/commits{/sha}","comments_url":"https://api.github.com/repos/joetsoi/ckan/comments{/number}","issue_comment_url":"https://api.github.com/repos/joetsoi/ckan/issues/comments/{number}","contents_url":"https://api.github.com/repos/joetsoi/ckan/contents/{+path}","compare_url":"https://api.github.com/repos/joetsoi/ckan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/joetsoi/ckan/merges","archive_url":"https://api.github.com/repos/joetsoi/ckan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/joetsoi/ckan/downloads","issues_url":"https://api.github.com/repos/joetsoi/ckan/issues{/number}","pulls_url":"https://api.github.com/repos/joetsoi/ckan/pulls{/number}","milestones_url":"https://api.github.com/repos/joetsoi/ckan/milestones{/number}","notifications_url":"https://api.github.com/repos/joetsoi/ckan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/joetsoi/ckan/labels{/name}","releases_url":"https://api.github.com/repos/joetsoi/ckan/releases{/id}","created_at":"2014-04-22T15:12:04Z","updated_at":"2014-07-29T14:46:45Z","pushed_at":"2015-02-04T11:58:03Z","git_url":"git://github.com/joetsoi/ckan.git","ssh_url":"git@github.com:joetsoi/ckan.git","clone_url":"https://github.com/joetsoi/ckan.git","svn_url":"https://github.com/joetsoi/ckan","homepage":"http://ckan.org/","size":75645,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ckan:master","ref":"master","sha":"bfab554772b7530fe18ceca8681c1db55386e547","user":{"login":"ckan","id":1630326,"avatar_url":"https://avatars.githubusercontent.com/u/1630326?v=3","gravatar_id":"","url":"https://api.github.com/users/ckan","html_url":"https://github.com/ckan","followers_url":"https://api.github.com/users/ckan/followers","following_url":"https://api.github.com/users/ckan/following{/other_user}","gists_url":"https://api.github.com/users/ckan/gists{/gist_id}","starred_url":"https://api.github.com/users/ckan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ckan/subscriptions","organizations_url":"https://api.github.com/users/ckan/orgs","repos_url":"https://api.github.com/users/ckan/repos","events_url":"https://api.github.com/users/ckan/events{/privacy}","received_events_url":"https://api.github.com/users/ckan/received_events","type":"Organization","site_admin":false},"repo":{"id":2750721,"name":"ckan","full_name":"ckan/ckan","owner":{"login":"ckan","id":1630326,"avatar_url":"https://avatars.githubusercontent.com/u/1630326?v=3","gravatar_id":"","url":"https://api.github.com/users/ckan","html_url":"https://github.com/ckan","followers_url":"https://api.github.com/users/ckan/followers","following_url":"https://api.github.com/users/ckan/following{/other_user}","gists_url":"https://api.github.com/users/ckan/gists{/gist_id}","starred_url":"https://api.github.com/users/ckan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ckan/subscriptions","organizations_url":"https://api.github.com/users/ckan/orgs","repos_url":"https://api.github.com/users/ckan/repos","events_url":"https://api.github.com/users/ckan/events{/privacy}","received_events_url":"https://api.github.com/users/ckan/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ckan/ckan","description":"CKAN is an open-source DMS (data management system) for powering data hubs and data portals. CKAN makes it easy to publish, share and use data. It powers datahub.io, catalog.data.gov and data.gov.uk among many other sites.","fork":false,"url":"https://api.github.com/repos/ckan/ckan","forks_url":"https://api.github.com/repos/ckan/ckan/forks","keys_url":"https://api.github.com/repos/ckan/ckan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ckan/ckan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ckan/ckan/teams","hooks_url":"https://api.github.com/repos/ckan/ckan/hooks","issue_events_url":"https://api.github.com/repos/ckan/ckan/issues/events{/number}","events_url":"https://api.github.com/repos/ckan/ckan/events","assignees_url":"https://api.github.com/repos/ckan/ckan/assignees{/user}","branches_url":"https://api.github.com/repos/ckan/ckan/branches{/branch}","tags_url":"https://api.github.com/repos/ckan/ckan/tags","blobs_url":"https://api.github.com/repos/ckan/ckan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ckan/ckan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ckan/ckan/git/refs{/sha}","trees_url":"https://api.github.com/repos/ckan/ckan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ckan/ckan/statuses/{sha}","languages_url":"https://api.github.com/repos/ckan/ckan/languages","stargazers_url":"https://api.github.com/repos/ckan/ckan/stargazers","contributors_url":"https://api.github.com/repos/ckan/ckan/contributors","subscribers_url":"https://api.github.com/repos/ckan/ckan/subscribers","subscription_url":"https://api.github.com/repos/ckan/ckan/subscription","commits_url":"https://api.github.com/repos/ckan/ckan/commits{/sha}","git_commits_url":"https://api.github.com/repos/ckan/ckan/git/commits{/sha}","comments_url":"https://api.github.com/repos/ckan/ckan/comments{/number}","issue_comment_url":"https://api.github.com/repos/ckan/ckan/issues/comments/{number}","contents_url":"https://api.github.com/repos/ckan/ckan/contents/{+path}","compare_url":"https://api.github.com/repos/ckan/ckan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ckan/ckan/merges","archive_url":"https://api.github.com/repos/ckan/ckan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ckan/ckan/downloads","issues_url":"https://api.github.com/repos/ckan/ckan/issues{/number}","pulls_url":"https://api.github.com/repos/ckan/ckan/pulls{/number}","milestones_url":"https://api.github.com/repos/ckan/ckan/milestones{/number}","notifications_url":"https://api.github.com/repos/ckan/ckan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ckan/ckan/labels{/name}","releases_url":"https://api.github.com/repos/ckan/ckan/releases{/id}","created_at":"2011-11-10T18:42:17Z","updated_at":"2015-02-04T10:54:53Z","pushed_at":"2015-02-04T11:00:32Z","git_url":"git://github.com/ckan/ckan.git","ssh_url":"git@github.com:ckan/ckan.git","clone_url":"https://github.com/ckan/ckan.git","svn_url":"https://github.com/ckan/ckan","homepage":"http://ckan.org/","size":169753,"stargazers_count":795,"watchers_count":795,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":447,"mirror_url":null,"open_issues_count":280,"forks":447,"open_issues":280,"watchers":795,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ckan/ckan/pulls/2262"},"html":{"href":"https://github.com/ckan/ckan/pull/2262"},"issue":{"href":"https://api.github.com/repos/ckan/ckan/issues/2262"},"comments":{"href":"https://api.github.com/repos/ckan/ckan/issues/2262/comments"},"review_comments":{"href":"https://api.github.com/repos/ckan/ckan/pulls/2262/comments"},"review_comment":{"href":"https://api.github.com/repos/ckan/ckan/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ckan/ckan/pulls/2262/commits"},"statuses":{"href":"https://api.github.com/repos/ckan/ckan/statuses/211cd50830a2e2c7c36de36ce708b0bd5166f44e"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":42,"deletions":0,"changed_files":1}}