{"action":"created","issue":{"url":"https://api.github.com/repos/krakjoe/pthreads/issues/531","labels_url":"https://api.github.com/repos/krakjoe/pthreads/issues/531/labels{/name}","comments_url":"https://api.github.com/repos/krakjoe/pthreads/issues/531/comments","events_url":"https://api.github.com/repos/krakjoe/pthreads/issues/531/events","html_url":"https://github.com/krakjoe/pthreads/issues/531","id":121865431,"number":531,"title":"Threads slowly eating memory ?","user":{"login":"metalwolf","id":1404459,"avatar_url":"https://avatars.githubusercontent.com/u/1404459?v=3","gravatar_id":"","url":"https://api.github.com/users/metalwolf","html_url":"https://github.com/metalwolf","followers_url":"https://api.github.com/users/metalwolf/followers","following_url":"https://api.github.com/users/metalwolf/following{/other_user}","gists_url":"https://api.github.com/users/metalwolf/gists{/gist_id}","starred_url":"https://api.github.com/users/metalwolf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metalwolf/subscriptions","organizations_url":"https://api.github.com/users/metalwolf/orgs","repos_url":"https://api.github.com/users/metalwolf/repos","events_url":"https://api.github.com/users/metalwolf/events{/privacy}","received_events_url":"https://api.github.com/users/metalwolf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-12-12T16:43:21Z","updated_at":"2015-12-28T08:25:41Z","closed_at":null,"body":"Hi @krakjoe \r\n\r\nI got the threaded server running for approx 48 hours, serving approx 1 million requests, and with constant 150-250 threads at the same time. \r\n\r\nAfter those 48 hours I noticed a strange behaviour, it is very slowly eating memory:\r\n\r\n![memory](https://cloud.githubusercontent.com/assets/1404459/11762867/8175ba0c-a0ba-11e5-96fc-dbaabf053da7.png)\r\n![threads](https://cloud.githubusercontent.com/assets/1404459/11762868/817c8c10-a0ba-11e5-84d9-2bd7601b44a7.png)\r\n\r\nMaking a fast calculation that would give approx 5Gb / 1M = 5K / thread \r\nSomething which is totally unseen on few threads / fast programs but on a long way run become visible.\r\n\r\nOn the manuals it just says that when the thread \"run\" ends, the thread is destroyed. Did I miss something ? Some garbage collector missing like in pools ( I dont use pools/workers) ? The main server only keeps the array of threaded clients and unset the clients when they are terminated \"normally\" or \"killed for any reason\"\r\n\r\nmainly:\r\n\r\nmainloop\r\n{\r\n  if (have to create client)\r\n  {\r\n     create client\r\n     $clients[] = the new client\r\n  }\r\n\r\n  foreach(clients as client)\r\n    if (client->isTerminated())\r\n       unset(clients[this client])   \r\n}\r\n\r\nThe quantity of clients effectively stays near 100-200 as reported on screen.\r\nSo the server should \"not\" eat the memory by itself ?\r\nI first thought of a local PHP error I left , but it seems not.\r\n\r\nThe interesting thing is that I destroy the threads but the CPU still is high. I mean, when I start the server it jump to 150 threads immediatly for the load but uses 5-10% CPU, and the CPU time is quite proportional to the quantity of memory.\r\nThreads are not fully destroyed and uses CPU and memory?\r\n\r\nAny ideas ? what could I do to help to find the error if it's thread related ? \r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/krakjoe/pthreads/issues/comments/167509539","html_url":"https://github.com/krakjoe/pthreads/issues/531#issuecomment-167509539","issue_url":"https://api.github.com/repos/krakjoe/pthreads/issues/531","id":167509539,"user":{"login":"krakjoe","id":2236138,"avatar_url":"https://avatars.githubusercontent.com/u/2236138?v=3","gravatar_id":"","url":"https://api.github.com/users/krakjoe","html_url":"https://github.com/krakjoe","followers_url":"https://api.github.com/users/krakjoe/followers","following_url":"https://api.github.com/users/krakjoe/following{/other_user}","gists_url":"https://api.github.com/users/krakjoe/gists{/gist_id}","starred_url":"https://api.github.com/users/krakjoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krakjoe/subscriptions","organizations_url":"https://api.github.com/users/krakjoe/orgs","repos_url":"https://api.github.com/users/krakjoe/repos","events_url":"https://api.github.com/users/krakjoe/events{/privacy}","received_events_url":"https://api.github.com/users/krakjoe/received_events","type":"User","site_admin":false},"created_at":"2015-12-28T08:25:41Z","updated_at":"2015-12-28T08:25:41Z","body":"```unset``` should immediately release memory, the only difference between $this->thing = null and unset($this->thing) is that the former will retain the entry in the properties store and so use *more* memory.\r\n\r\nRunning the code above, I cannot see any leak, memory usage goes up and down both reported by Zend and ps, so, what am I looking at ?"}}