Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Concurrency extension to use transaction-level (xact) advisory locks #1439

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

bensheldon
Copy link
Owner

Connected to #1433.

@bensheldon bensheldon added the enhancement New feature or request label Jul 18, 2024
@bensheldon
Copy link
Owner Author

Via @benoittgt

  • “commit” might involve slightly more work as it finalizes the transaction in the transaction log
  • “rollback” might do slightly less work as it doesn’t need to finalize anything in the transaction log

@bensheldon
Copy link
Owner Author

Running a trivial benchmark shows no difference:

Benchmark.ips do |x|
  x.report("with rollback") do
    Rails.application.executor.wrap do
      GoodJob::Job.transaction do
        GoodJob::Job.advisory_lock_key("the-key") do
          GoodJob::Job.count
          raise ActiveRecord::Rollback
        end
      end
    end
  end

  x.report("with commit") do
    Rails.application.executor.wrap do
      GoodJob::Job.transaction do
        GoodJob::Job.advisory_lock_key("the-key") do
          GoodJob::Job.count
        end
      end
    end
  end

  x.compare!
end




❯ bundle exec ruby scripts/benchmark_transaction_advisory_locks.rb
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]
Warming up --------------------------------------
       with rollback     1.000 i/100ms
         with commit    20.000 i/100ms
Calculating -------------------------------------
       with rollback    289.829 (±32.4%) i/s -      1.270k in   5.003833s
         with commit    239.911 (±14.6%) i/s -      1.180k in   5.031871s

Comparison:
       with rollback:      289.8 i/s
         with commit:      239.9 i/s - same-ish: difference falls within error

❯ bundle exec ruby scripts/benchmark_transaction_advisory_locks.rb
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]
Warming up --------------------------------------
       with rollback    30.000 i/100ms
         with commit    19.000 i/100ms
Calculating -------------------------------------
       with rollback    229.932 (±21.7%) i/s -      1.110k in   5.056057s
         with commit    262.627 (±15.6%) i/s -      1.292k in   5.041111s

Comparison:
         with commit:      262.6 i/s
       with rollback:      229.9 i/s - same-ish: difference falls within error

@bensheldon bensheldon merged commit eaace45 into main Jul 31, 2024
14 checks passed
@bensheldon bensheldon deleted the xact-advisory-lock branch July 31, 2024 01:04
bensheldon added a commit that referenced this pull request Jul 31, 2024
…y locks (#1439)

* Convert Concurrency extension to use transaction-level (xact) advisory locks

* Perform a rollback on the transaction

* Add Advisory Lock benchmark script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

1 participant