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

feat: support portal restTemplate Client connection pool config #5200

Merged

Conversation

youngzil
Copy link
Contributor

@youngzil youngzil commented Aug 14, 2024

What's the purpose of this PR

Portal 模块 RestTemplate 支持配置 HTTP最大连接池和每个路由的连接大小 详见 #5199

Which issue(s) this PR fixes:

Fixes #5199

Brief changelog

support portal restTemplate Client connection pool config

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

  • New Features

    • Added support for configuring a connection pool for the HTTP client, enhancing performance and efficiency in handling multiple connections.
    • Introduced new configuration methods to manage connection pooling parameters.
  • Documentation

    • Updated changelog to reflect the addition of connection pool configuration support for the HTTP client.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 14, 2024
Copy link
Contributor

coderabbitai bot commented Aug 14, 2024

Walkthrough

The recent changes enhance the RestTemplateFactory and PortalConfig classes by integrating a connection management feature, allowing configuration of the maximum connection pool and connections per route for HTTP requests. This optimization aims to improve performance and resource management, addressing limitations observed during high-load scenarios in the Apollo portal.

Changes

File Path Change Summary
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java Implemented a PoolingHttpClientConnectionManager to optimize HTTP connection management.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java Added connectPoolMaxTotal() and connectPoolMaxPerRoute() methods for customizable connection settings.
CHANGES.md Documented the new feature supporting connection pool configuration for the RestTemplate client.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PortalConfig
    participant RestTemplateFactory
    participant ConnectionManager

    User->>PortalConfig: Request config values
    PortalConfig-->>User: Return connectPoolMaxTotal() and connectPoolMaxPerRoute()
    User->>RestTemplateFactory: Create RestTemplate with config
    RestTemplateFactory->>ConnectionManager: Set connection limits
    ConnectionManager-->>RestTemplateFactory: Connection pool ready
Loading

Assessment against linked issues

Objective Addressed Explanation
Support configuration of HTTP max connection pool and per route size (#5199)
Resolve high load performance issues by optimizing connection management

Poem

🐰 In the portal where bunnies hop,
New connections bloom, never stop!
Pooling brings joy, in a swift ballet,
HTTP flows free, come what may!
Hooray for the changes, let’s cheer and play! 🎉


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

github-actions bot commented Aug 14, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c28eb49 and 12c654e.

Files selected for processing (2)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java (2 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (1 hunks)
Additional comments not posted (4)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java (2)

64-66: Ensure connection pool parameters are correctly configured.

The PoolingHttpClientConnectionManager is correctly initialized and configured using portalConfig. This change aligns with the PR objectives to enhance connection management.


70-70: Verify connection manager integration.

The connection manager is correctly set in the HttpClientBuilder. Ensure that this integration is thoroughly tested to confirm improved performance under high-load scenarios.

Verification successful

Connection Manager Integration Verified

The RetryableRestTemplateTest.java file contains several tests that verify the behavior of the RetryableRestTemplate, which uses RestTemplateFactory to create RestTemplate instances. These tests simulate various scenarios, including server availability and request retries, which indirectly test the integration of the connection manager by ensuring the RestTemplate behaves correctly under different conditions.

  • The tests cover scenarios such as:
    • Handling of server timeouts and retries.
    • Correct handling of HTTP methods (GET, POST, PUT, DELETE).
    • Use of access tokens in requests.

These tests provide confidence that the connection manager integration is functioning as expected, particularly in handling network issues and retries.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of connection manager in RestTemplateFactory.

# Test: Search for usages of RestTemplateFactory to ensure the connection manager is utilized.
rg --type java -A 5 $'RestTemplateFactory'

Length of output: 9302


Script:

#!/bin/bash
# Search for test cases involving RestTemplateFactory to verify connection manager integration.
rg --type java -A 10 'RestTemplateFactory' | grep -i 'test'

Length of output: 57


Script:

#!/bin/bash
# Search for test files related to components using RestTemplateFactory to verify connection manager integration.
rg --type java -l 'ConfigReleaseWebhookNotifier|AdminServiceAddressLocator|RetryableRestTemplate|SystemInfoController' | grep -i 'test'

Length of output: 228


Script:

#!/bin/bash
# Display the contents of RetryableRestTemplateTest.java to verify connection manager integration.
cat apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/RetryableRestTemplateTest.java

Length of output: 20641

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (2)

176-178: Default value for maximum total connections.

The method connectPoolMaxTotal correctly retrieves the property with a default value of 20. Ensure this default aligns with typical usage scenarios.


180-182: Default value for maximum connections per route.

The method connectPoolMaxPerRoute correctly retrieves the property with a default value of 2. Ensure this default aligns with typical usage scenarios.

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 12c654e and 516557b.

Files selected for processing (1)
  • CHANGES.md (1 hunks)
Additional comments not posted (1)
CHANGES.md (1)

17-17: Changelog entry looks good!

The new entry in the changelog is clear and provides a useful reference to the pull request for more details.

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 516557b and 53f2f68.

Files selected for processing (1)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java

@nobodyiam
Copy link
Member

Please complete the CLA by following the instructions provided by the CLA bot.
Once done, you may proceed to refresh the codebase and update the CHANGES.md file.

@nobodyiam nobodyiam added this to the 2.4.0 milestone Aug 17, 2024
@youngzil
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 53f2f68 and 3c8fcc6.

Files selected for processing (1)
  • CHANGES.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGES.md

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 21, 2024
@nobodyiam nobodyiam merged commit f4a0236 into apolloconfig:master Aug 21, 2024
7 of 8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2024
@youngzil youngzil deleted the feature-portal-rest-pool-config branch August 22, 2024 06:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Portal 模块 RestTemplate 支持配置 HTTP最大连接池和每个路由的连接大小
2 participants