Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
This is a true story about how using the wrong method caused the app to hang for our users, and how it increased our database CPU usage by up to 10 times! You probably are using this same method in your app right now. Find out what you should use instead.
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
In this lightning talk, Moncef Belyamani presents a cautionary tale on how a seemingly innocuous coding method can lead to severe performance issues in an application. He recounts his experience working on a Rails app for the Department of Veterans Affairs, detailing how the use of '.count' in database queries caused significant CPU strain and application hang-ups. Belyamani emphasizes the importance of understanding the consequences of different methods in Rails and outlines alternative and more efficient ways to check for empty results. Key points discussed include: - **The Problem**: Moncef reveals that calling '.count' on Active Record relations translates to expensive count queries, particularly on large tables, leading to performance degradation. - **The Context**: He describes his role at Truss and how they were modernizing legacy systems for enhancing veteran services, leading to the Caseflow project focused on processing claims more efficiently. - **The Investigation**: That winter day, after noticing high CPU usage and a related exception in Sentry, Moncef was tasked with troubleshooting the issue which was linked to an inefficient query method. - **Identifying the Culprit**: Spotting the infamous '.count' in the code, he shared how such a method could greatly slow down the application, especially given the growing size of the documents table. - **The Solution**: Belyamani proposed replacing '.count > 0' with '.any', which yielded a drastic reduction in CPU utilization—an approximate five to ten times decrease. This clean-up extended beyond just this one instance, as he found and fixed several other occurrences of '.count' in the codebase. - **Lessons Learned**: The talk concludes with valuable action items: developers should audit their code for occurrences of '.count', consider adding timestamps to tables for better tracking, and monitor SQL performance more closely to prevent future issues. Ultimately, Moncef encourages developers to be proactive in optimizing database interactions and highlights the impact that small changes can have on application performance, especially in systems dealing with large datasets. He ends by inviting attendees to explore more details and resources related to the discussion on his blog.
Suggest modifications
Cancel