You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "mxsm (via GitHub)" <gi...@apache.org> on 2023/03/03 16:25:44 UTC
[GitHub] [rocketmq] mxsm opened a new pull request, #6239: [ISSUE #6236]Optimize ThreadLocalIndex replace Integer with AtomicInteger
mxsm opened a new pull request, #6239:
URL: https://github.com/apache/rocketmq/pull/6239
**Make sure set the target branch to `develop`**
## What is the purpose of the change
<!--
If this PR fixes a GitHub issue, please add `fixes #<XXX>` or `closes #<XXX>`. Please refer to the documentation for more information:
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->
fix #6236
## Brief changelog
- Optimize ThreadLocalIndex replace Integer with AtomicInteger
## Verifying this change
XXXX
Follow this checklist to help us incorporate your contribution quickly and easily. Notice, `it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR`.
- [x] Make sure there is a [Github issue](https://github.com/apache/rocketmq/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
- [x] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/apache/rocketmq/tree/master/test).
- [x] Run `mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test` to make sure integration-test pass.
- [ ] If this contribution is large, please file an [Apache Individual Contributor License Agreement](http://www.apache.org/licenses/#clas).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #6236]Optimize ThreadLocalIndex replace Integer with AtomicInteger [rocketmq]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6239:
URL: https://github.com/apache/rocketmq/pull/6239#issuecomment-2028958885
This PR was closed because it has been inactive for 3 days since being marked as stale.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #6236]Optimize ThreadLocalIndex replace Integer with AtomicInteger [rocketmq]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6239:
URL: https://github.com/apache/rocketmq/pull/6239#issuecomment-2026352065
This PR is stale because it has been open for 365 days with no activity. It will be closed in 3 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] mxsm commented on pull request #6239: [ISSUE #6236]Optimize ThreadLocalIndex replace Integer with AtomicInteger
Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on PR #6239:
URL: https://github.com/apache/rocketmq/pull/6239#issuecomment-1453799771
```java
public class ThreadLocalIndexOptimize {
private final ThreadLocal<AtomicInteger> threadLocalIndex = new ThreadLocal<>();
private final Random random = new Random();
private final static int POSITIVE_MASK = 0x7FFFFFFF;
public int incrementAndGet() {
AtomicInteger index = this.threadLocalIndex.get();
if (null == index) {
index = new AtomicInteger(random.nextInt());
threadLocalIndex.set(index);
}
return Math.abs(index.incrementAndGet() & POSITIVE_MASK);
}
@Override
public String toString() {
return "ThreadLocalIndex{" +
"threadLocalIndex=" + threadLocalIndex.get() +
'}';
}
}
```
benchmark
```java
@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 3, time = 1)
@Measurement(iterations = 5, time = 5)
@Fork(1)
@State(value = Scope.Benchmark)
@OutputTimeUnit(TimeUnit.SECONDS)
public class ThreadLocalIndexBenchmark {
private ThreadLocalIndex index = new ThreadLocalIndex();
private ThreadLocalIndexOptimize optimize = new ThreadLocalIndexOptimize();
@Benchmark
@Threads(1)
public void threadLocalIndex_1() {
index.incrementAndGet();
}
@Benchmark
@Threads(1)
public void threadLocalIndexOptimize_1() {
optimize.incrementAndGet();
}
@Benchmark
@Threads(8)
public void threadLocalIndex_8() {
index.incrementAndGet();
}
@Benchmark
@Threads(8)
public void threadLocalIndexOptimize_8() {
optimize.incrementAndGet();
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(ThreadLocalIndexBenchmark.class.getSimpleName())
.result("result.json")
.resultFormat(ResultFormatType.JSON).build();
new Runner(opt).run();
}
}
```
result:
```
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
ThreadLocalIndexBenchmark.threadLocalIndexOptimize_1 thrpt 5 170159993.824 ± 1318284.420 ops/s
ThreadLocalIndexBenchmark.threadLocalIndexOptimize_8 thrpt 5 1055535073.108 ± 23152204.877 ops/s
ThreadLocalIndexBenchmark.threadLocalIndex_1 thrpt 5 234089647.698 ± 16986301.995 ops/s
ThreadLocalIndexBenchmark.threadLocalIndex_8 thrpt 5 776787743.442 ± 50277549.179 ops/s
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] mxsm commented on pull request #6239: [ISSUE #6236]Optimize ThreadLocalIndex replace Integer with AtomicInteger
Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on PR #6239:
URL: https://github.com/apache/rocketmq/pull/6239#issuecomment-1455731117
@RongtongJin PTAL~
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #6236]Optimize ThreadLocalIndex replace Integer with AtomicInteger [rocketmq]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #6239: [ISSUE #6236]Optimize ThreadLocalIndex replace Integer with AtomicInteger
URL: https://github.com/apache/rocketmq/pull/6239
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org