# Speeding up Development Reloads when changing Ruby files

**URL:** <https://meta.discourse.org/t/speeding-up-development-reloads-when-changing-ruby-files/72923>\
**Category:** Development\
**Created:** [27 أكتوبر 2017، 2:25م UTC](https://meta.discourse.org/t/speeding-up-development-reloads-when-changing-ruby-files/72923 "2017-10-27T14:25:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [30 أكتوبر 2017، 3:32ص UTC](https://meta.discourse.org/t/speeding-up-development-reloads-when-changing-ruby-files/72923/2 "2017-10-30T03:32:05Z")

</div>

Thanks for all the legwork here @eviltrout it made it way easier to fix.

Fixed per:

[https://github.com/discourse/discourse/commit/7ca08216bdf6436764a2b8964d06f4bcd84e5eb4](https://github.com/discourse/discourse/commit/7ca08216bdf6436764a2b8964d06f4bcd84e5eb4)

### How I debugged this?

I edited my local copy of `active_record/connection_adapters/abstract/connnection_pool.rb`

In `def checkout` I added:

```plaintext
def checkout(checkout_timeout = @checkout_timeout)
  c = checkout_and_verify(acquire_connection(checkout_timeout))
  puts "CHECKOUT-#{c.object_id}" + "-"* 10
  puts caller.grep(/discourse/)
  puts "-" * 10
  c
end

```

In `def checkin` I added:

```plaintext
def checkin(conn)
  puts "CHECKIN-#{conn.object_id}" + "-"* 10
  puts caller.grep(/discourse/)
  puts "-" * 10

   ... 

```

This revealed 2 spots that were not returning connections to the pool.

Minor problem was on boot, plugins sometimes opened connections to the db without giving connection back to pool.

> <https://github.com/discourse/discourse/blob/main/config/application.rb#L211>

Major issue was the defer queue that was never releasing its connection (fixed here)

> <https://github.com/discourse/discourse/blob/7ca08216bdf6436764a2b8964d06f4bcd84e5eb4/lib/scheduler/defer.rb#L78>

The `defer` queue exists to kick off lightweight background work we have the is too light to belong in Sidekiq (like increasing user view counts and stuff like that). In a `puma` environment it runs in a background thread, in a `unicorn` environment it runs between requests.

Enjoy 😇

---

_[View the full topic](https://meta.discourse.org/t/speeding-up-development-reloads-when-changing-ruby-files/72923)._
