Rails API Profiler: A Lightweight Performance Tool for North East Developers
In the fast-paced world of software development, understanding the performance of our applications is crucial. For developers in North East India, who often work on Rails API applications, a new tool has emerged that provides lightweight, local insight into the performance of their APIs: the Rails API Profiler.
The Birth of a Ruby Gem
Like many developers, Sparsh Shukla, the creator of Rails API Profiler, had long contemplated building a Ruby gem. However, the project kept getting postponed. One day, he decided to stop overthinking and just ship. This decision led to the creation of his first Ruby gem: rails_api_profiler.
Addressing Common Performance Questions
While working on Rails API applications, developers often encounter questions about performance: Which API endpoints are slow? How many database queries does a request trigger? Is the bottleneck in application code or the database? The Rails API Profiler aims to provide quick answers to these questions.
How It Works
The Rails API Profiler is an amiddleware-based performance profiler for Rails APIs. It logs essential metrics per request, including request duration, ActiveRecord query count, total database execution time, and more, without requiring any controller changes or monkey patching. The gem uses Rack middleware to measure request time, ActiveSupport::Notifications to track SQL queries, thread-local storage for request-scoped stats, and a Railtie for automatic Rails integration.
Lessons Learned and Future Applications
Building the Rails API Profiler offered Sparsh valuable insights into Rails middleware and instrumentation, structuring Rails-compatible gems, and the importance of shipping early rather than waiting for perfection. The tool can be particularly beneficial for developers in North East India, as it helps them optimize their Rails API applications for better performance and user experience.