amistad icon indicating copy to clipboard operation
amistad copied to clipboard

Major performance issue after upgrading to 0.9.x

Open patroza opened this issue 12 years ago • 1 comments

Running PostgreSQL, after upgrading to 0.9.x there's been major spikes on our db server, with average response times running well into the 2seconds.

Here's some of the EXPLAIN's: duration: 409.997 ms statement: SELECT 1 duration: 1268.868 ms statement: SELECT "users".* FROM "users" WHERE (("users"."id" IN (SELECT "friendships"."friend_id" FROM "friendships" WHERE (("friendships"."friendable_id" = 16190 AND "friendships"."pending" = 'f' AND "friendships"."blocker_id" IS NULL))) OR "users"."id" IN (SELECT "friendships"."friendable_id" FROM "friendships" WHERE (("friendships"."friend_id" = 16190 AND "friendships"."pending" = 'f' AND "friendships"."blocker_id" IS NULL))))) duration: 1210.892 ms statement: SELECT "users".* FROM "users" WHERE (("users"."id" IN (SELECT "friendships"."friend_id" FROM "friendships" WHERE (("friendships"."friendable_id" = 16017 AND "friendships"."pending" = 'f' AND "friendships"."blocker_id" IS NULL))) OR "users"."id" IN (SELECT "friendships"."friendable_id" FROM "friendships" WHERE (("friendships"."friend_id" = 16017 AND "friendships"."pending" = 'f' AND "friendships"."blocker_id" IS NULL))))) duration: 1053.002 ms statement: SELECT "users".* FROM "users" WHERE (("users"."id" IN (SELECT "friendships"."friend_id" FROM "friendships" WHERE (("friendships"."friendable_id" = 77299 AND "friendships"."pending" = 'f' AND "friendships"."blocker_id" IS NULL))) OR "users"."id" IN (SELECT "friendships"."friendable_id" FROM "friendships" WHERE (("friendships"."friend_id" = 77299 AND "friendships"."pending" = 'f' AND "friendships"."blocker_id" IS NULL)))))

After reverting to https://github.com/raw1z/amistad/commit/f436251bf906a1fc97628aa93a4d14cada5a7e51 all seems to be well again

I suppose some of it could be appointed to Query caches etc needing to catch up, but the issue might be terminal. Perhaps some extra indexes are required?

In any case, I had to revert because our production app was unresponsive.

patroza avatar Nov 01 '12 21:11 patroza

the 'friends' method has been modified in order to return an ActiveRecord::Relation instead of an Array. the above query is generated by this new method. I'm investigating on the performance issue.

raw1z avatar Nov 01 '12 22:11 raw1z