solid_queue: development env, high CPU usage

Trying a default install of solid_queue 1.1.2, with a still empty queue DB. Ruby 3.1.6, Rails 7.1.5.1, Ubuntu 22.04, MySQL 5.7. No Puma.

When I run rails solid_queue:start, CPU usage goes crazy. It looks like this:

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   2859 user    20   0 1032208 183844  17444 R  93.7   1.1   0:22.42 solid-queue-supervisor(1.1.2): supervising 2875, 2878
   2875 user    20   0  966868 179332   8632 R  79.7   1.1   0:17.48 solid-queue-dispatcher(1.1.2): dispatching every 1 seconds
   2878 user    20   0  900884 179320   8360 R  74.7   1.1   0:16.36 solid-queue-worker(1.1.2): waiting for jobs in *
    295 mysql     20   0 2717988 290808  15516 S  38.9   1.8   0:16.64 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

and it never goes down. I tried changing the polling to 500/50 or even slower, but it doesn’t change anything at all in usage.

Is it some misconfiguration issue?

Nothing suspicious in the logs as I can see.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@alex29ua this should be fixed now in version 1.1.3, thanks to @hms! 🙇‍♀

@rosa

Thank you for the help with the code cleanup to get this PR out faster.

@rosa @alex29ua @markivancho

PR submitted as committed. Hopefully it’s acceptable.

@rosa – the one failure in test run is because of a timing problem based on container load rather than a real issue.

@hms

@rosa

I already have a PR to fix another small, zero impact bug (but a bug never the less) that I had found during my debugging this issue. I’m happy to address the Interruptible issue in that PR.

I do need some guidance on the SQ team’s preferred solution. If SQ is going to support Ruby 3.1, then I have to replace the current version of Interruptible.rb with the original version – there is no ruby 3.1 work around with the Thread::Queue based implementation.

The catch is: Ruby 3.1 hits EOL (for security patches – which I assume is an effective EOL for 99%+ of users) in 2 months. If we’re really only considering supporting 3.1 for 2 to X months, then I would propose to craft an initializer that includes the correct version of Interruptible based on the Ruby version.

Please let me know your preferences and I’ll supply a PR.

Also, if SQ is going to support multiple versions of Ruby, would you be open to me creating a PR for the GitHub actions to test across supported rubies? When I created the original interruptible PR, I made the assumption that 3.3.1 was the baseline ruby because it was set in .ruby_version and the GitHub actions as the only tested ruby.

@rosa, @markivancho, @alex29ua

I tracked problem down.

In above referenced PR, Interruptible.rb was reimplemented using Thread::Queue and Queue.pop(timeout:).

Ruby 3.1.* does not support the Queue.pop method with a keyword argument of timeout and that results in the queue pop call raising an exception, effectively returning immediately. This explains the high CPU utilization since Workers and Dispatchers effectively never sleep between poll loops.

The timeout argument is supported in Ruby 3.2 which is why everything worked when @alex29ua upgraded to Ruby 3.2.

What made this issue a little harder to track down is Queue.pop is called inside of a Concurrent::Promises.future, which swallowed the exception because I “cleverly” failed to add an exception handler because “such simple code could never fail” (hangs head in shame 😳 ).

When I initially responded that I tested Ruby 3.1 - 3.6, that was because I transposed 3.1.3 with 3.3.1 (which was the earliest version I did test with). Sorry for the delay that this caused in resolving the issue.

@hms

@rosa nicely spotted! 1.0.2 works perfectly, I can barely find it in the processes. 1.1.0 and up - goes full on with CPU again.

I only have mysql5.7 to test with, though I set the recommended use_skip_locked = false in all the cases.

tried with this queue.yml config

default: &default
  dispatchers:
    - polling_interval: 30
      batch_size: 500
  workers:
    - queues: "*"
      threads: 1
      processes: 1
      polling_interval: 10

to make it really slooow - but I still get the same huge load.