GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][ml] Share immutable publish positions with cached entries (… · apache/pulsar@7bcae18

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl
    • OpAddEntry.java
  • microbench/src/main/java/org/apache
    • bookkeeper/mledger/impl
      • PublishPositionSharingBenchmark.java
    • pulsar/client/impl
      • FastThreadLocalBenchmarkExecutor.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java‎

Copy file name to clipboardExpand all lines: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public void run() {
266266

267267
// ctx will contain a Position instance only in the case of ShadowManagedLedgerImpl
268268
long ledgerId = ledger != null ? ledger.getId() : ((Position) ctx).getLedgerId();
269+
Position lastEntry = PositionFactory.create(ledgerId, entryId);
269270

270271
// Handle caching for tailing reads
271272
if (ml.shouldCacheAddedEntry()) {
@@ -275,15 +276,14 @@ public void run() {
275276
// use the number of active cursors as the expected read count
276277
expectedReadCount = ml.getActiveCursors().size();
277278
}
278-
EntryImpl entry = EntryImpl.create(ledgerId, entryId, data, expectedReadCount);
279+
EntryImpl entry = EntryImpl.create(lastEntry, data, expectedReadCount);
279280
entry.setDecreaseReadCountOnRelease(false);
280281
// EntryCache.insert: duplicates entry by allocating new entry and data. so, recycle entry after calling
281282
// insert
282283
ml.entryCache.insert(entry);
283284
entry.release();
284285
}
285286

286-
Position lastEntry = PositionFactory.create(ledgerId, entryId);
287287
ManagedLedgerImpl.ENTRIES_ADDED_COUNTER_UPDATER.incrementAndGet(ml);
288288
ml.lastConfirmedEntry = lastEntry;
289289

Collapse file

‎microbench/src/main/java/org/apache/bookkeeper/mledger/impl/PublishPositionSharingBenchmark.java‎

Copy file name to clipboard
+98Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bookkeeper.mledger.impl;
20+
21+
import io.netty.buffer.ByteBuf;
22+
import io.netty.buffer.PooledByteBufAllocator;
23+
import io.netty.util.concurrent.FastThreadLocalThread;
24+
import java.util.concurrent.TimeUnit;
25+
import org.apache.bookkeeper.mledger.Position;
26+
import org.apache.bookkeeper.mledger.PositionFactory;
27+
import org.openjdk.jmh.annotations.Benchmark;
28+
import org.openjdk.jmh.annotations.BenchmarkMode;
29+
import org.openjdk.jmh.annotations.Fork;
30+
import org.openjdk.jmh.annotations.Measurement;
31+
import org.openjdk.jmh.annotations.Mode;
32+
import org.openjdk.jmh.annotations.OutputTimeUnit;
33+
import org.openjdk.jmh.annotations.Param;
34+
import org.openjdk.jmh.annotations.Scope;
35+
import org.openjdk.jmh.annotations.Setup;
36+
import org.openjdk.jmh.annotations.State;
37+
import org.openjdk.jmh.annotations.TearDown;
38+
import org.openjdk.jmh.annotations.Warmup;
39+
40+
/** Isolates position construction with real pooled entry copies; does not model persistence or cache maps. */
41+
@State(Scope.Thread)
42+
@BenchmarkMode(Mode.AverageTime)
43+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
44+
@Warmup(iterations = 3, time = 1)
45+
@Measurement(iterations = 5, time = 1)
46+
@Fork(2)
47+
public class PublishPositionSharingBenchmark {
48+
@Param({"false", "true"})
49+
public boolean sharePosition;
50+
51+
@Param({"false", "true"})
52+
public boolean cacheEntry;
53+
54+
private ByteBuf data;
55+
private long nextEntryId;
56+
private volatile Position cachedPosition;
57+
private volatile Position confirmedPosition;
58+
59+
@Setup
60+
public void setup() {
61+
if (!FastThreadLocalThread.currentThreadWillCleanupFastThreadLocals()) {
62+
throw new IllegalStateException("Run with FastThreadLocalBenchmarkExecutor in the fork JVM");
63+
}
64+
data = PooledByteBufAllocator.DEFAULT.directBuffer(128).writeZero(128);
65+
}
66+
67+
@Benchmark
68+
public long completePublish() {
69+
long entryId = nextEntryId++;
70+
Position lastEntry = sharePosition ? PositionFactory.create(1, entryId) : null;
71+
if (cacheEntry) {
72+
EntryImpl entry = sharePosition ? EntryImpl.create(lastEntry, data, 0)
73+
: EntryImpl.create(1, entryId, data, 0);
74+
try {
75+
EntryImpl copy = EntryImpl.createWithRetainedDuplicate(entry.getPosition(), entry.getDataBuffer(), 0);
76+
try {
77+
cachedPosition = copy.getPosition();
78+
} finally {
79+
copy.release();
80+
}
81+
} finally {
82+
entry.release();
83+
}
84+
}
85+
if (!sharePosition) {
86+
lastEntry = PositionFactory.create(1, entryId);
87+
}
88+
confirmedPosition = lastEntry;
89+
return lastEntry.getEntryId();
90+
}
91+
92+
@TearDown
93+
public void tearDown() {
94+
cachedPosition = null;
95+
confirmedPosition = null;
96+
data.release();
97+
}
98+
}
Collapse file

‎microbench/src/main/java/org/apache/pulsar/client/impl/FastThreadLocalBenchmarkExecutor.java‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.client.impl;
20+
21+
import io.netty.util.concurrent.DefaultThreadFactory;
22+
import java.util.concurrent.LinkedBlockingQueue;
23+
import java.util.concurrent.ThreadPoolExecutor;
24+
import java.util.concurrent.TimeUnit;
25+
26+
/** Optional JMH executor for benchmarks that need Netty's thread-local recycling to be active. */
27+
public class FastThreadLocalBenchmarkExecutor extends ThreadPoolExecutor {
28+
public FastThreadLocalBenchmarkExecutor(int threads, String name) {
29+
super(threads, threads, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),
30+
new DefaultThreadFactory(name));
31+
}
32+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.