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: updated the max connection pool size and datasourceDestroy method #36631

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

NilanshBansal
Copy link
Contributor

@NilanshBansal NilanshBansal commented Oct 1, 2024

Description

  • This PR updates the max connection pool size for MySQL datasource from 5 to 20 as from the logs we found out that the maximum connections are always getting used.
  • This PR also updates the datasourceDestroy method for MySQL plugin to ensure the graceful shutdown of thread takes places and ensures the connection is closed as opposed to immediate termination of the thread earlier which does not ensure closure of existing connection.
SCR-20241001-lbq-2

Fixes #34028

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11129233985
Commit: 04617ce
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Tue, 01 Oct 2024 16:44:48 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Increased the maximum connection pool size for MySQL from 5 to 20, allowing for more concurrent database connections.
  • Bug Fixes

    • Improved the termination process of the SSH tunnel thread for better handling during datasource destruction.

Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The pull request introduces modifications to the MySqlPlugin and MySqlDatasourceUtils classes. In MySqlPlugin, the datasourceDestroy method now uses a thread interruption approach for handling SSH tunnel termination instead of forceful stopping. In MySqlDatasourceUtils, the maximum connection pool size has been increased from 5 to 20, allowing for greater concurrency in database connections. These changes aim to enhance resource management and connection handling within the application.

Changes

File Change Summary
app/server/appsmith-plugins/mysqlPlugin/src/main/java/com/external/plugins/MySqlPlugin.java Updated datasourceDestroy method to replace stop() with interrupt() for graceful thread termination.
app/server/appsmith-plugins/mysqlPlugin/src/main/java/com/external/utils/MySqlDatasourceUtils.java Increased MAX_CONNECTION_POOL_SIZE from 5 to 20 to allow more concurrent database connections.
app/server/appsmith-server/src/test/java/com/appsmith/server/connectionpoolconfig/configurations/ConnectionPoolConfigCETest.java Updated test to reflect new default value of connectionPoolMaxSize from 5 to 20.

Assessment against linked issues

Objective Addressed Explanation
Address memory leak issue in database integration (#34028)

Possibly related PRs

Suggested labels

Enhancement, Task

Suggested reviewers

  • nidhi-nair
  • sondermanish
  • subrata71

Poem

In the land of code where plugins reside,
A thread's gentle nudge, no longer a slide.
Connections now flourish, a pool wide and grand,
With graceful exits, the code takes a stand.
Cheers to the changes, let performance soar,
In Appsmith's realm, we open the door! 🎉


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 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 Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Integrations Product Issues related to a specific integration MariaDB MariaDB datasource Needs Triaging Needs attention from maintainers to triage Production Query & JS Pod Issues related to the query & JS Pod labels Oct 1, 2024
@NilanshBansal NilanshBansal self-assigned this Oct 1, 2024
@NilanshBansal NilanshBansal added the ok-to-test Required label for CI label Oct 1, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
app/server/appsmith-plugins/mysqlPlugin/src/main/java/com/external/plugins/MySqlPlugin.java (1)

695-695: Class, pay attention to this important change!

The modification in the datasourceDestroy method is a significant improvement in how we handle the SSH tunnel thread. Instead of using the deprecated stop() method, we're now using interrupt(). This is a much safer way to terminate a thread.

Let's break it down:

  1. The old way (stop()) was like abruptly unplugging a computer - it could leave things in an inconsistent state.
  2. The new way (interrupt()) is like politely asking the thread to finish up its work - it's safer and allows for proper cleanup.

This change aligns with best practices in concurrent programming. Well done! However, remember that the thread should be designed to respond to interrupts for this to work effectively.

As a follow-up, consider reviewing the implementation of the SSH tunnel thread to ensure it properly handles interrupts. This might involve checking for Thread.interrupted() in any long-running operations within the thread.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2e2146d and e6853ee.

📒 Files selected for processing (2)
  • app/server/appsmith-plugins/mysqlPlugin/src/main/java/com/external/plugins/MySqlPlugin.java (1 hunks)
  • app/server/appsmith-plugins/mysqlPlugin/src/main/java/com/external/utils/MySqlDatasourceUtils.java (1 hunks)

This comment was marked as outdated.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e6853ee and 04617ce.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/connectionpoolconfig/configurations/ConnectionPoolConfigCETest.java (1 hunks)

This comment was marked as outdated.

@sneha122
Copy link
Contributor

sneha122 commented Oct 1, 2024

@NilanshBansal Are there any test cases that I need to test on DP?

@NilanshBansal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Oct 1, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11125505971.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36631.
recreate: .

Copy link

github-actions bot commented Oct 1, 2024

Deploy-Preview-URL: https://ce-36631.dp.appsmith.com

@NilanshBansal
Copy link
Contributor Author

@sneha122 @manish535 please check the performance of the same application when imported in appsmith production VS the DP (containing these changes). It is very evident that the above change fixes the problem at hand and improves the performance of the application thereby ensuring early release of memory.
App Json imported: https://drive.google.com/file/d/16dy2_9I9T11wb3ZIUBgxvaxSn0V8yapT/view?usp=sharing
Maria DB Creds can be found in Servers & Credentials notion doc.
Appsmith Prod App: https://app.appsmith.com/app/memory-leak-a-force-issue/page2-66fbf8e2762fac387e09b19b
DP App: https://ce-36631.dp.appsmith.com/app/memory-leak-a-force-issue/page2-66fbf1f4370ad96d89adeddb

Screen.Recording.2024-10-01.at.7.00.05.PM.mov

@NilanshBansal
Copy link
Contributor Author

@NilanshBansal Are there any test cases that I need to test on DP?

@sneha122 I have already verified this on the DP compared with Appsmith prod as of now. We don't need any more testing on this.
#36631 (comment)

@NilanshBansal NilanshBansal added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Oct 1, 2024
@sondermanish
Copy link
Contributor

The PR looks good to go! waiting for the Cypress to pass

@NilanshBansal
Copy link
Contributor Author

The failing test is unrelated to the changes in this PR, it is also failing in an empty commit PR. Ref: #36637
image

Hence updating the Tag to let the cypress pass

@NilanshBansal NilanshBansal added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Oct 1, 2024
@NilanshBansal NilanshBansal merged commit 00fb934 into release Oct 2, 2024
104 of 108 checks passed
@NilanshBansal NilanshBansal deleted the fix/issue-34028/memory-leak-mysql branch October 2, 2024 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Integrations Product Issues related to a specific integration MariaDB MariaDB datasource Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Query & JS Pod Issues related to the query & JS Pod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: [aforce] Memory leak issue in Appsmith's database integration causing website downtime.
3 participants