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

fix: Scheduling the heavy database ops on bounded elastic thread pool for Ms-sql #39176

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

trishaanand
Copy link
Contributor

@trishaanand trishaanand commented Feb 11, 2025

Description

Production is seeing high number of pod restarts causing downtime. It seems to be correlated with user MS-SQL query triggers. On the hypothesis that its indeed the plugin executions causing this, it could be the datasource create taking up redis thread pool (possibly because of an upstream scheduling of a task on it)

Sample log lines displaying the behaviour (only user email removed from the logs) :
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 - boundedElastic-13: datasourceCreate() called for MSSQL plugin.
Feb 11 05:38:05 appsmith-d6d86999-6djmx appsmith backend stdout | [2025-02-11 00:08:05,357] [lettuce-epollEventLoop-10-3] requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<> traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 - lettuce-epollEventLoop-10-3: Connecting to SQL Server db
Feb 11 05:38:05 appsmith-d6d86999-6djmx appsmith backend stdout | [2025-02-11 00:08:05,381] [lettuce-epollEventLoop-10-3] requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<> traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 - HikariPool-3 - Starting...
Feb 11 05:38:15 appsmith-d6d86999-6djmx appsmith backend stdout | [2025-02-11 00:08:15,346] [parallel-2] requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<> traceId=bda95acf0e182c48037214d5173d0ac9 spanId=88ee6f7444f698dc - parallel-2: Action Query3 with id 67aa94d7b95fcb7ea3d5512c execution time : 10002 ms

This was possibly brought on by the following PR :
#38818

As part of the above PR, scheduleOn statement moved from Mono.callable() which creates its own subscription chain to outside. This could be causing the heavy database ops moving to event loop instead of bounded elastic.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/test sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13265007600
Commit: 3e758fb
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Tue, 11 Feb 2025 14:53:05 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Refactor
    • Optimized the connection creation workflow to defer resource initialization until required. This enhancement improves the scheduling and responsiveness of establishing connections, ensuring that system resources are utilized more efficiently during runtime.

@trishaanand trishaanand added the ok-to-test Required label for CI label Feb 11, 2025
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Walkthrough

The pull request updates the datasourceCreate method in the MssqlPluginExecutor class within the MSSQL plugin. The method now wraps its execution in Mono.defer() to delay fetching the connection pool size until subscription. The logging statement for connecting to the SQL Server database has also been moved inside the Mono.defer() block, maintaining logging functionality while changing the execution context. Error handling and overall logic remain unchanged.

Changes

File(s) Change Summary
app/server/appsmith-plugins/.../MssqlPlugin.java Updated the datasourceCreate method in MssqlPluginExecutor: Wrapped the logic in Mono.defer() for lazy execution; moved logging inside Mono.defer().

Sequence Diagram(s)

sequenceDiagram
    participant S as Subscriber
    participant E as MssqlPluginExecutor
    participant OS as Scheduler
    S->>E: Invoke datasourceCreate()
    E->>E: Wrap execution with Mono.defer()
    E->>E: Call getMaxConnectionPoolSize() inside Mono.defer()
    E->>OS: Delegate execution with subscribeOn(scheduler)
    OS-->>E: Execute the connection creation task
    E-->>S: Return HikariDataSource
Loading

Possibly related PRs

Suggested labels

Task

Suggested reviewers

  • NilanshBansal

Poem

In the realm where deferred calls hold sway,
The connection pool awakens in a brand-new way.
Lazy loading takes its rightful stage,
With scheduling that sets the code on a graceful page.
Here's to clean flows and runtime delight,
A symphony of code in the soft glow of night!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da66b85 and 3e758fb.

📒 Files selected for processing (1)
  • app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
  • GitHub Check: server-unit-tests / server-unit-tests

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the Bug Something isn't working label Feb 11, 2025
@trishaanand trishaanand requested a review from sneha122 February 11, 2025 14:27
@trishaanand trishaanand merged commit 9aa065b into release Feb 11, 2025
47 checks passed
@trishaanand trishaanand deleted the fix/ms-sql-connection-pool-bounded-elastic branch February 11, 2025 14:54
trishaanand added a commit that referenced this pull request Feb 11, 2025
… for Ms-sql (#39176)

## Description
Production is seeing high number of pod restarts causing downtime. It
seems to be correlated with user MS-SQL query triggers. On the
hypothesis that its indeed the plugin executions causing this, it could
be the datasource create taking up redis thread pool (possibly because
of an upstream scheduling of a task on it)

Sample log lines displaying the behaviour (only user email removed from
the logs) :
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 -
boundedElastic-13: datasourceCreate() called for MSSQL plugin.
Feb 11 05:38:05 appsmith-d6d86999-6djmx appsmith backend stdout |
[2025-02-11 00:08:05,357] [lettuce-epollEventLoop-10-3]
requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<>
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 -
lettuce-epollEventLoop-10-3: Connecting to SQL Server db
Feb 11 05:38:05 appsmith-d6d86999-6djmx appsmith backend stdout |
[2025-02-11 00:08:05,381] [lettuce-epollEventLoop-10-3]
requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<>
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 -
HikariPool-3 - Starting...
Feb 11 05:38:15 appsmith-d6d86999-6djmx appsmith backend stdout |
[2025-02-11 00:08:15,346] [parallel-2]
requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<>
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=88ee6f7444f698dc -
parallel-2: Action Query3 with id 67aa94d7b95fcb7ea3d5512c execution
time : 10002 ms

This was possibly brought on by the following PR : 
#38818

As part of the above PR, scheduleOn statement moved from Mono.callable()
which creates its own subscription chain to outside. This could be
causing the heavy database ops moving to event loop instead of bounded
elastic.

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/test sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13265007600>
> Commit: 3e758fb
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13265007600&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Tue, 11 Feb 2025 14:53:05 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Optimized the connection creation workflow to defer resource
initialization until required. This enhancement improves the scheduling
and responsiveness of establishing connections, ensuring that system
resources are utilized more efficiently during runtime.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 12, 2025
… for Ms-sql (appsmithorg#39176)

## Description
Production is seeing high number of pod restarts causing downtime. It
seems to be correlated with user MS-SQL query triggers. On the
hypothesis that its indeed the plugin executions causing this, it could
be the datasource create taking up redis thread pool (possibly because
of an upstream scheduling of a task on it)

Sample log lines displaying the behaviour (only user email removed from
the logs) :
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 -
boundedElastic-13: datasourceCreate() called for MSSQL plugin.
Feb 11 05:38:05 appsmith-d6d86999-6djmx appsmith backend stdout |
[2025-02-11 00:08:05,357] [lettuce-epollEventLoop-10-3]
requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<>
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 -
lettuce-epollEventLoop-10-3: Connecting to SQL Server db
Feb 11 05:38:05 appsmith-d6d86999-6djmx appsmith backend stdout |
[2025-02-11 00:08:05,381] [lettuce-epollEventLoop-10-3]
requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<>
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=00fdca579a517b66 -
HikariPool-3 - Starting...
Feb 11 05:38:15 appsmith-d6d86999-6djmx appsmith backend stdout |
[2025-02-11 00:08:15,346] [parallel-2]
requestId=dd547055-d9bc-41ed-b7b4-03b0de691984 userEmail=<>
traceId=bda95acf0e182c48037214d5173d0ac9 spanId=88ee6f7444f698dc -
parallel-2: Action Query3 with id 67aa94d7b95fcb7ea3d5512c execution
time : 10002 ms

This was possibly brought on by the following PR : 
appsmithorg#38818

As part of the above PR, scheduleOn statement moved from Mono.callable()
which creates its own subscription chain to outside. This could be
causing the heavy database ops moving to event loop instead of bounded
elastic.

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/test sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13265007600>
> Commit: 3e758fb
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13265007600&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Tue, 11 Feb 2025 14:53:05 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Optimized the connection creation workflow to defer resource
initialization until required. This enhancement improves the scheduling
and responsiveness of establishing connections, ensuring that system
resources are utilized more efficiently during runtime.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants