Skip to content

Instantly share code, notes, and snippets.

@toshimaru
Last active January 23, 2022 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshimaru/c33cfdb2e1b2540ff0481092e8c36745 to your computer and use it in GitHub Desktop.
Save toshimaru/c33cfdb2e1b2540ff0481092e8c36745 to your computer and use it in GitHub Desktop.
unicorn 6.1 reduces memory usage.

Environment

  • Ruby 3.1 (ruby:3.1 docker image)
  • unicorn 6.1
  • Rails 6.1

Workload

  • Run unicorn with 4 worker processes
  • Request 100 times to unicorn app

unicorn 6.1 without epoll

  def prep_readers(readers)
-   wtr = Unicorn::Waiter.prep_readers(readers)
-   @timeout *= 500 # to milliseconds for epoll, but halved
-   wtr
- rescue
    require_relative 'select_waiter'
    @timeout /= 2.0 # halved for IO.select
    Unicorn::SelectWaiter.new
  end
# free -h # before 100 requests
               total        used        free      shared  buff/cache   available
Mem:           1.9Gi       805Mi       169Mi       199Mi       1.0Gi       797Mi
Swap:          1.0Gi       155Mi       868Mi

# free -h # after 100 requests
               total        used        free      shared  buff/cache   available
Mem:           1.9Gi       943Mi        85Mi       192Mi       956Mi       670Mi
Swap:          1.0Gi       163Mi       860Mi

unicorn 6.1 with epoll

  def prep_readers(readers)
    wtr = Unicorn::Waiter.prep_readers(readers)
    @timeout *= 500 # to milliseconds for epoll, but halved
    wtr
- rescue
-   require_relative 'select_waiter'
-   @timeout /= 2.0 # halved for IO.select
-   Unicorn::SelectWaiter.new
  end
# free -h # before 100 requests
               total        used        free      shared  buff/cache   available
Mem:           1.9Gi       802Mi       160Mi       192Mi       1.0Gi       811Mi
Swap:          1.0Gi       163Mi       860Mi
# free -h # after 100 requests
               total        used        free      shared  buff/cache   available
Mem:           1.9Gi       805Mi       156Mi       192Mi       1.0Gi       808Mi
Swap:          1.0Gi       163Mi       860Mi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment