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 the issue with repeatedly building plugin RouterFunction for CustomEndpoints #4890

Merged
merged 6 commits into from Nov 24, 2023

Conversation

guqing
Copy link
Member

@guqing guqing commented Nov 22, 2023

What type of PR is this?

/kind bug
/area core
/milestone 2.11.x

What this PR does / why we need it:

修复当使用 ab 压测插件提供的 CustomEndpoint 时会出现 OOM 的问题

see #4889 for more details.

how to test it?

  1. 首先通过 -Xmx128m -Xms128m JVM Option 指定 halo 的 heap space 为 128m
  2. 使用 ab 测试由插件通过 implements CustomEndpoint 提供的任意 API 是否会出现 OOM,例如:
ab -n 10000 -c 100 -A 'admin:admin' http://localhost:8090/apis/doc.halo.run/v1alpha1/projects/halo/languages
  1. 期望一切正常,示例日志如下:
➤ ab -n 10000 -c 100 -A 'admin:admin' http://localhost:8090/apis/doc.halo.run/v1alpha1/projects/halo/languages
This is ApacheBench, Version 2.3 <$Revision: 1901567 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Which issue(s) this PR fixes:

Fixes #4889

Does this PR introduce a user-facing change?

修复因错误构建插件的路由可能导致 OOM 的问题。

@f2c-ci-robot f2c-ci-robot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Nov 22, 2023
@f2c-ci-robot f2c-ci-robot bot added this to the 2.11.x milestone Nov 22, 2023
@f2c-ci-robot f2c-ci-robot bot added the area/core Issues or PRs related to the Halo Core label Nov 22, 2023
@f2c-ci-robot f2c-ci-robot bot requested review from LIlGG and ruibaby November 22, 2023 09:53
@guqing
Copy link
Member Author

guqing commented Nov 22, 2023

/cherry-pick release-2.10

@halo-dev-bot
Copy link
Collaborator

@guqing: once the present PR merges, I will cherry-pick it on top of release-2.10 in a new PR and assign it to you.

In response to this:

/cherry-pick release-2.10

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

codecov bot commented Nov 22, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (457e059) 56.88% compared to head (78efe64) 56.81%.
Report is 15 commits behind head on main.

Files Patch % Lines
.../run/halo/app/plugin/AggregatedRouterFunction.java 0.00% 9 Missing ⚠️
.../halo/app/plugin/PluginApplicationInitializer.java 0.00% 1 Missing ⚠️
.../halo/app/plugin/event/HaloPluginStartedEvent.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4890      +/-   ##
============================================
- Coverage     56.88%   56.81%   -0.08%     
+ Complexity     2975     2971       -4     
============================================
  Files           514      515       +1     
  Lines         16912    16913       +1     
  Branches       1273     1273              
============================================
- Hits           9621     9609      -12     
- Misses         6750     6762      +12     
- Partials        541      542       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

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

如果想要最小修改来修复这个问题,可以参考一下:cd8f1c2

@guqing
Copy link
Member Author

guqing commented Nov 22, 2023

如果想要最小修改来修复这个问题,可以参考一下:cd8f1c2

那么插件被停止后被缓存起来的已经生成的 router function如何移除呢🧐

@JohnNiang
Copy link
Member

如果想要最小修改来修复这个问题,可以参考一下:cd8f1c2

那么插件被停止后被缓存起来的已经生成的 router function如何移除呢🧐

你是对的。我确实忽略了这一点。

不过我更建议在构建 ApplicationContext 的时候注册 RouterFunction,而不是在插件启动时才异步注册。

@guqing
Copy link
Member Author

guqing commented Nov 23, 2023

如果想要最小修改来修复这个问题,可以参考一下:cd8f1c2

那么插件被停止后被缓存起来的已经生成的 router function如何移除呢🧐

你是对的。我确实忽略了这一点。

不过我更建议在构建 ApplicationContext 的时候注册 RouterFunction,而不是在插件启动时才异步注册。

那个改动不在此pr做,有计划在后续重构一下一些启动需要的步骤作为创建 context 的步骤,目前确实太分散了

@JohnNiang JohnNiang changed the title fix: OOM occured when using ab to test custom endpoints provided by plugin Fix the issue with repeatedly building plugin RouterFunction for CustomEndpoints Nov 23, 2023
Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

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

/approve

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 23, 2023
@JohnNiang JohnNiang removed this from the 2.11.x milestone Nov 24, 2023
@JohnNiang JohnNiang added this to the 2.11.0 milestone Nov 24, 2023
@guqing
Copy link
Member Author

guqing commented Nov 24, 2023

/ping @halo-dev/sig-halo

Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

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

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Nov 24, 2023
Copy link

f2c-ci-robot bot commented Nov 24, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JohnNiang, ruibaby

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@JohnNiang JohnNiang merged commit 57a1f2e into halo-dev:main Nov 24, 2023
4 checks passed
@halo-dev-bot
Copy link
Collaborator

@guqing: new pull request created: #4908

In response to this:

/cherry-pick release-2.10

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

f2c-ci-robot bot pushed a commit that referenced this pull request Nov 24, 2023
…nction for CustomEndpoints (#4908)

This is an automated cherry-pick of #4890

/assign guqing

```release-note
修复因错误构建插件的路由可能导致 OOM 的问题
```
@guqing guqing deleted the bugfix/4889 branch November 24, 2023 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/core Issues or PRs related to the Halo Core kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用 ab 测试访问插件提供的某个 API 一万次会出现 OOM
4 participants