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

CNJR-2412: Set database connection pool size based on worker thread count #2875

Merged
merged 5 commits into from
Aug 15, 2023

Conversation

micahlee
Copy link
Contributor

@micahlee micahlee commented Jul 28, 2023

Desired Outcome

The desired outcome of this PR is to prevent a database thread pool exhaustion in Conjur.

Implemented Changes

The primary change in this PR is to set the maximum database connections in the connection pool based on the number of threads per web worker, to mitigate the opportunity for connection exhaustion or for a request to time out waiting for a DB connection.

By default, the number of connections allowed in the pool is 1.2x the number of threads.

In addition to the core change this PR makes a couple of quality of life improvements that may be reviewed by commit:

  • Factors out the Sequel ORM settings to a separate Rails initializer.
  • Adds basic input validation and error reporting for the web worker, thread, and connection pool settings.
  • Fixes a couple of issues currently present in the Changelog.

Connected Issue/Story

CyberArk internal issue ID: CNJR-2412

Definition of Done

At least 1 todo must be completed in the sections below for the PR to be
merged.

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

We do not currently have any test suites that can execute tests at the scale to exhibit the faulty behavior this PR addresses. This approach, however, was validated in the field, and the overall configuration approach is validated through our E2E test suites.

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: [insert issue ID]
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@micahlee micahlee force-pushed the cnjr-2412-db-connection-pool branch 3 times, most recently from 31478c8 to 1e1e714 Compare August 10, 2023 16:07
- New flag to `conjurctl server` command called `--no-migrate` which allows for skipping
the database migration step when starting the server.
[cyberark/conjur#2895](https://github.com/cyberark/conjur/pull/2895)

### Changed
- The database thread pool max connection size is now based on the number of
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

@micahlee micahlee marked this pull request as ready for review August 10, 2023 20:39
@micahlee micahlee requested a review from a team as a code owner August 10, 2023 20:39
Copy link
Contributor

@imheresamir imheresamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of very minor nits. Reviewed and looks good to me.

This fixes a "Fixed" block under the "Unreleased"
section and a duplicate "Added" block in the
version currently under development.
Rather than raise an ArgumentError, raise
a message with details on which configuration
value failed to parse and how to fix it.
Rather than configure puma directly in the
appliance, use the Conjur application settings
and config to set the puma threads.
@micahlee micahlee force-pushed the cnjr-2412-db-connection-pool branch from 1e1e714 to 58f8db5 Compare August 15, 2023 18:25
@micahlee
Copy link
Contributor Author

micahlee commented Aug 15, 2023

Thanks @imheresamir, that was definitely a goof during history cleanup. That is fixed now. Mind re-approving? Actually it looks like it didn't auto-dismiss your prior approval. 🤔

@micahlee micahlee requested a review from imheresamir August 15, 2023 18:26
@codeclimate
Copy link

codeclimate bot commented Aug 15, 2023

Code Climate has analyzed commit 58f8db5 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Style 1

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 88.4% (0.2% change).

View more on Code Climate.

@micahlee micahlee merged commit ec6fe4b into master Aug 15, 2023
@micahlee micahlee deleted the cnjr-2412-db-connection-pool branch August 15, 2023 19:47
@UberKitten
Copy link

@micahlee What was the thinking behind using 1.2 connections per thread?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants