{"action":"created","issue":{"url":"https://api.github.com/repos/thiagopradi/octopus/issues/280","repository_url":"https://api.github.com/repos/thiagopradi/octopus","labels_url":"https://api.github.com/repos/thiagopradi/octopus/issues/280/labels{/name}","comments_url":"https://api.github.com/repos/thiagopradi/octopus/issues/280/comments","events_url":"https://api.github.com/repos/thiagopradi/octopus/issues/280/events","html_url":"https://github.com/thiagopradi/octopus/issues/280","id":44508776,"number":280,"title":"Huge performance problems with rails >= 4.0","user":{"login":"dalyons","id":43060,"avatar_url":"https://avatars.githubusercontent.com/u/43060?v=3","gravatar_id":"","url":"https://api.github.com/users/dalyons","html_url":"https://github.com/dalyons","followers_url":"https://api.github.com/users/dalyons/followers","following_url":"https://api.github.com/users/dalyons/following{/other_user}","gists_url":"https://api.github.com/users/dalyons/gists{/gist_id}","starred_url":"https://api.github.com/users/dalyons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dalyons/subscriptions","organizations_url":"https://api.github.com/users/dalyons/orgs","repos_url":"https://api.github.com/users/dalyons/repos","events_url":"https://api.github.com/users/dalyons/events{/privacy}","received_events_url":"https://api.github.com/users/dalyons/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":43,"created_at":"2014-09-30T22:41:16Z","updated_at":"2016-02-23T11:05:25Z","closed_at":null,"body":"tl;dr - something in the octopus AR metaprogramming is causing huge amounts of constant cache invalidations, which is disastrous for performance. \r\n\r\nSo we have a bigish, high traffic rails API site. Recently did the bump from 3.2 to 4.0, and our 95% response times basically doubled, and response times were choppy all over the place. Using New Relic, we were able to see this suspicious graph:\r\n\r\n![screen shot 2014-09-30 at 2 46 01 pm](https://cloud.githubusercontent.com/assets/43060/4467108/41d19e10-48ec-11e4-8e63-06b9b5f707d2.png)\r\n\r\nAfter a lot of troubleshooting using dtrace & the pretty cool Busted gem https://github.com/simeonwillbanks/busted , we were able to verify that under rails 4.0 we were invalidating the ruby constant cache sometimes up to hundreds of times per request (as opposed to zero times in rails 3.2) \r\n\r\nRemoving ar-octopus and changing nothing else solved the problem and led to this: \r\n\r\n![screen shot 2014-09-30 at 2 39 29 pm](https://cloud.githubusercontent.com/assets/43060/4467137/a30ee70a-48ec-11e4-9a94-4b4e3f33dc43.png)\r\n\r\nAnd halved our request time.\r\n\r\nI'm not sure what meta-programming exactly octopus is doing, but its doing some class definition inside the request cycle in rails 4, which is resetting the constant cache sometimes up to 100s of times per request. \r\n\r\nFrom the traces generated by Busted, I suspect it's something to do with the AR association proxies. Bigger, more complex requests that load lots of dependent models seems to make the invalidations skyrocket.\r\n"},"comment":{"url":"https://api.github.com/repos/thiagopradi/octopus/issues/comments/187654010","html_url":"https://github.com/thiagopradi/octopus/issues/280#issuecomment-187654010","issue_url":"https://api.github.com/repos/thiagopradi/octopus/issues/280","id":187654010,"user":{"login":"anhkind","id":308785,"avatar_url":"https://avatars.githubusercontent.com/u/308785?v=3","gravatar_id":"","url":"https://api.github.com/users/anhkind","html_url":"https://github.com/anhkind","followers_url":"https://api.github.com/users/anhkind/followers","following_url":"https://api.github.com/users/anhkind/following{/other_user}","gists_url":"https://api.github.com/users/anhkind/gists{/gist_id}","starred_url":"https://api.github.com/users/anhkind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anhkind/subscriptions","organizations_url":"https://api.github.com/users/anhkind/orgs","repos_url":"https://api.github.com/users/anhkind/repos","events_url":"https://api.github.com/users/anhkind/events{/privacy}","received_events_url":"https://api.github.com/users/anhkind/received_events","type":"User","site_admin":false},"created_at":"2016-02-23T11:05:24Z","updated_at":"2016-02-23T11:05:24Z","body":"@nickmarden :+1:  \r\nI can see that your PR #357 passed all the specs, which is awesome!"}}