horizonzy opened a new pull request, #4038:
URL: https://github.com/apache/bookkeeper/pull/4038
If the BufferChannel is BufferedReadChannel, the size won't change. We can
cache the fileSize to avoid system calls.
### Performance tests.
The entry log `f` file holds 1GB data.
```
-rw-r--r--@ 1 horizon staff 1.0G 7 26 17:47 f.log
```
#### 1. Test DefaultEntryLogger.scanEntryLog
```
public static void main(String[] args) throws IOException {
ServerConfiguration serverConfiguration = new ServerConfiguration();
serverConfiguration.setLedgerDirNames(new
String[]{"/Users/horizon/Downloads/bk1/bk-data"});
DefaultEntryLogger defaultEntryLogger = new
DefaultEntryLogger(serverConfiguration);
long l = System.currentTimeMillis();
AtomicInteger entryCount = new AtomicInteger();
defaultEntryLogger.scanEntryLog(15, new EntryLogScanner() {
@Override
public boolean accept(long ledgerId) {
return true;
}
@Override
public void process(long ledgerId, long offset, ByteBuf entry)
throws IOException {
entryCount.incrementAndGet();
}
});
long spend = System.currentTimeMillis() - l;
System.out.println("Scan entry end, entry count: " +
entryCount.get());
System.out.println("Spend: " + spend);
}
```
Before this pr:
```
Scan entry end, entry count: 17886769
Spend: 37273
```
After this pr:
```
Scan entry end, entry count: 17886769
Spend: 3363
```
**10x performance improvement**
#### 2. Test DefaultEntryLogger.readFromLogChannel
```
public static void main(String[] args) throws IOException {
ServerConfiguration serverConfiguration = new ServerConfiguration();
serverConfiguration.setLedgerDirNames(new
String[]{"/Users/horizon/Downloads/bk1/bk-data"});
DefaultEntryLogger defaultEntryLogger = new
DefaultEntryLogger(serverConfiguration);
long l = System.currentTimeMillis();
BufferedReadChannel channel =
defaultEntryLogger.getChannelForLogId(15);
int pos = 0;
//Read total 1gb data from the BufferedReadChannel.
long gb = 1024 * 1024 * 1024;
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.heapBuffer(10);
while (pos < gb) {
defaultEntryLogger.readFromLogChannel(15, channel, byteBuf, 0);
pos += byteBuf.readableBytes();
byteBuf.clear();
}
long spend = System.currentTimeMillis() - l;
System.out.println("Spend: " + spend);
}
```
Before this pr:
```
Spend: 69810
```
After this pr:
```
Spend: 2338
```
**30x performance improvement**
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]