Use io.netty.recycler.ratio
directly (#10253)
Motivation
1. It's inable to collect all object because RATIO is always >=1 after
`safeFindNextPositivePowerOfTwo`
2. Enable drop object in `WeakOrderQueue`(commit:
71860e5b94
) enlarge the drop ratio. We
can subtly control the overall drop ratio by using `io.netty.recycler.ratio` directly,
Modification
- Remove `safeFindNextPositivePowerOfTwo` before set the ratio
Results
Able to disable drop when recycle object
This commit is contained in:
parent
7f54c6d90d
commit
447d6b3924
@ -82,7 +82,7 @@ public abstract class Recycler<T> {
|
||||
// By default we allow one push to a Recycler for each 8th try on handles that were never recycled before.
|
||||
// This should help to slowly increase the capacity of the recycler while not be too sensitive to allocation
|
||||
// bursts.
|
||||
RATIO = safeFindNextPositivePowerOfTwo(SystemPropertyUtil.getInt("io.netty.recycler.ratio", 8));
|
||||
RATIO = max(0, SystemPropertyUtil.getInt("io.netty.recycler.ratio", 8));
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
if (DEFAULT_MAX_CAPACITY_PER_THREAD == 0) {
|
||||
@ -138,7 +138,7 @@ public abstract class Recycler<T> {
|
||||
|
||||
protected Recycler(int maxCapacityPerThread, int maxSharedCapacityFactor,
|
||||
int ratio, int maxDelayedQueuesPerThread) {
|
||||
interval = safeFindNextPositivePowerOfTwo(ratio);
|
||||
interval = max(0, ratio);
|
||||
if (maxCapacityPerThread <= 0) {
|
||||
this.maxCapacityPerThread = 0;
|
||||
this.maxSharedCapacityFactor = 1;
|
||||
|
@ -26,8 +26,14 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class RecyclerTest {
|
||||
|
||||
private static Recycler<HandledObject> newRecycler(int max) {
|
||||
return new Recycler<HandledObject>(max) {
|
||||
private static Recycler<HandledObject> newRecycler(int maxCapacityPerThread) {
|
||||
return newRecycler(maxCapacityPerThread, 2, 8, 2);
|
||||
}
|
||||
|
||||
private static Recycler<HandledObject> newRecycler(int maxCapacityPerThread, int maxSharedCapacityFactor,
|
||||
int ratio, int maxDelayedQueuesPerThread) {
|
||||
return new Recycler<HandledObject>(maxCapacityPerThread, maxSharedCapacityFactor, ratio,
|
||||
maxDelayedQueuesPerThread) {
|
||||
@Override
|
||||
protected HandledObject newObject(
|
||||
Recycler.Handle<HandledObject> handle) {
|
||||
@ -122,6 +128,19 @@ public class RecyclerTest {
|
||||
object2.recycle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecycleDisableDrop() {
|
||||
Recycler<HandledObject> recycler = newRecycler(1024, 2, 0, 2);
|
||||
HandledObject object = recycler.get();
|
||||
object.recycle();
|
||||
HandledObject object2 = recycler.get();
|
||||
assertSame(object, object2);
|
||||
object2.recycle();
|
||||
HandledObject object3 = recycler.get();
|
||||
assertSame(object, object3);
|
||||
object3.recycle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to make sure bug #2848 never happens again
|
||||
* https://github.com/netty/netty/issues/2848
|
||||
|
Loading…
Reference in New Issue
Block a user