Comments (8)
我更新了benchmark,之前的分区数量太低。测试下来stormpot最快,比fop快一倍。commons最差。
稍后我会考虑如何继续改进。我可能会改用disruptor模式,这个一直在我计划中,只是没空弄。
非常感谢!
from fast-object-pool.
你可以直接运行benchmark内的代码。测试完了告诉我结果。
大概看了一眼你的测试,你需要去掉Jedis的代码, 因为borrow、return很快,但是io很慢。你可以测试借没有io的对象,比如StringBuilder的追加测试。另外你必须增加finally去return,不管是fop还是common pool没有finally后面都会挂。
from fast-object-pool.
benchmark好久没有跑了,package name不对,刚刚改了一下。
from fast-object-pool.
感谢回复
我修改了beanmark代码,由StringBuilder换成了Jedis,loop保持一致。已经提交到https://github.com/wyzssw/poolcompare,测试结果如下
-----------warm up------------
Average Response Time:1
Average Througput Per Second:82645
Average Response Time:0.49
Average Borrow Time:0.00
Average Return Time:0.00
Average Througput Per Second:101833
-----------fast object pool------------
Average Response Time:0
Average Througput Per Second:115048
Average Response Time:1
Average Througput Per Second:94913
Average Response Time:1
Average Througput Per Second:93997
Average Response Time:2
Average Througput Per Second:88261
Average Response Time:3
Average Througput Per Second:78864
Average Response Time:3
Average Througput Per Second:80415
Average Response Time:4
Average Througput Per Second:74963
Average Response Time:4
Average Througput Per Second:76739
Average Response Time:5
Average Througput Per Second:68592
Average Response Time:6
Average Througput Per Second:62964
Average Response Time:7
Average Througput Per Second:60300
Average Response Time:9
Average Througput Per Second:55788
------------Apache commons pool-----------
Average Response Time:0.78
Average Borrow Time:0.00
Average Return Time:0.00
Average Througput Per Second:63710
Average Response Time:1.55
Average Borrow Time:0.76
Average Return Time:0.00
Average Througput Per Second:62066
Average Response Time:2.41
Average Borrow Time:1.58
Average Return Time:0.00
Average Througput Per Second:59995
Average Response Time:3.17
Average Borrow Time:2.34
Average Return Time:0.01
Average Througput Per Second:59601
Average Response Time:3.77
Average Borrow Time:2.98
Average Return Time:0.01
Average Througput Per Second:62735
Average Response Time:4.46
Average Borrow Time:3.68
Average Return Time:0.02
Average Througput Per Second:63479
Average Response Time:5.15
Average Borrow Time:4.37
Average Return Time:0.04
Average Througput Per Second:63377
Average Response Time:5.72
Average Borrow Time:4.95
Average Return Time:0.05
Average Througput Per Second:64961
Average Response Time:6.44
Average Borrow Time:5.67
Average Return Time:0.10
Average Througput Per Second:64795
Average Response Time:6.74
Average Borrow Time:6.00
Average Return Time:0.09
Average Througput Per Second:66747
Average Response Time:7.81
Average Borrow Time:7.01
Average Return Time:0.11
Average Througput Per Second:61944
Average Response Time:8.45
Average Borrow Time:7.67
Average Return Time:0.17
Average Througput Per Second:63465
从上述测试来看,fop 2x于common-pool2;如果fop的objectQueue采用LinkedTransferQueue,性能应该会更好(https://github.com/chrisvest/stormpot就是这么做的)
实际使用场景大多是针对连接池对象做池化,StringBuilder对象不需要池化,单纯追求borrow和return的性能意义不大.
return时我是加了finally的.
from fast-object-pool.
stormpot我没有用过,我新建了一个分支,就叫做stormpot,包含了stormpot的benchmark,但是我不知道为什么,在我的测试里stormpot会hang。你可以看一眼么?
测试的时候你可以初始化jedis,borrow/return, 但我建议别真去请求get("x") 因为这样测试下来大多数的时间都在jedis上了,这时候pool本身占比例太小了, 很可能用任何性能还说得过去的pool测试出来的结果差别都不大。
我特别喜欢这个数据库连接池:https://github.com/brettwooldridge/HikariCP
这哥们工作在日本,我看他的benchmark的时候用的是一个stub driver,其实是个假的数据库,创建连接发statement其实都不做任何io操作。他这样测试出来的就只是pool本身的性能,会准确很多。
from fast-object-pool.
看了一下,Mypoolable构造函数需要设置slot,以下是diff
diff --git a/src/benchmark/BenchmarkStormpot.java b/src/benchmark/BenchmarkStormpot.java
index baec9a1..031cc7b 100755
--- a/src/benchmark/BenchmarkStormpot.java
+++ b/src/benchmark/BenchmarkStormpot.java
@@ -11,8 +11,10 @@ public class BenchmarkStormpot extends Benchmark {
static class MyPoolable implements stormpot.Poolable {
private StringBuilder test;
+ private final Slot slot;
- public MyPoolable() {
+ public MyPoolable(Slot slot) {
+ this.slot = slot;
test = new StringBuilder();
}
@@ -22,7 +24,7 @@ public class BenchmarkStormpot extends Benchmark {
@Override
public void release() {
-
+ slot.release(this);
}
}
@@ -33,7 +35,7 @@ public class BenchmarkStormpot extends Benchmark {
Config<MyPoolable> config = new Config<>().setAllocator(new Allocator<MyPoolable>() {
@Override
public MyPoolable allocate(Slot slot) throws Exception {
- return new MyPoolable();
+ return new MyPoolable(slot);
}
@Override
关于benchmark是否进行io操作,可以对io时间和borrowreturn分别记录,我在com.justdebugit.pool.compare.PoolCompare就已经做了划分: 总消耗和borrow消耗
from fast-object-pool.
stormpot确实不错,不过他是为了解决特定的问题,当thread local效果不好的时候, 他会慢一些。比如t1拿到对象预处理一下然后丢给t2去处理和归还。
https://medium.com/@chrisvest/released-stormpot-2-1-c31509142757
BlazePool is optimised for the case where the threads that use the pool, stick around and use it over and over, and they only claim one object at a time.
刚才瞄了一眼他的代码,发现他快有一个很大的原因是因为Slot有padding,避免了false sharing。这点很棒。我顺便也加入了furious object pool的benchmark.
from fast-object-pool.
现在更新到2.1, 使用disruptor之后,速度提升了一些。但是同线程每次borrow/return一个的情况下还是比不过stormpot。最近比较忙,日后有时间吧benchmark单独拿出来一个repo,把同线程多个borrow的情况也测试一下。
from fast-object-pool.
Related Issues (20)
- Call back on scavenge HOT 4
- Use Poolable in using block. HOT 2
- More intelligent logics of borrowing objects HOT 3
- Stop supporting jdk1.7 HOT 2
- chain setters in PoolConfig
- does it support keyed object ? HOT 2
- Add benchmark graph to readme.md
- Risk condition causing thread blocked HOT 5
- pom file needed
- Endless loop with partition shutdown HOT 2
- Scavenger cannot be disabled
- travis needed
- Performance stats HOT 2
- JaCoCo dependency pulls many unnecessary Maven modules into users' own projects HOT 3
- release for both JDK8, and 11+ HOT 1
- optional slf4j logging HOT 1
- More flexible scavenger model HOT 4
- graceful shutdown HOT 1
- add returnToPool method to Poolable HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast-object-pool.