Re #142: Agrona does not like array backed buffers due to mis-alignment performance hit. It does not allow to turn off the check on arm. (#143)

This commit is contained in:
Tomasz Kowalczewski authored and GitHub committed 2025-02-09 13:18:27 +01:00
1 parent aa7c6eb09d
commit 1931a0b59b
16 files changed
+52 -123

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ Logging should be lightweight and not interfere with main business tasks of thre
Asking the logging subsystem to log a message should be as CPU efficient as possible.
That's a truism. Apart from computation itself there are many other causes of jitter (varying speed of code execution).
Thread can be slowed down by excessive allocations, by initialization code running in constructors of unnecessarily allocated objects,
by garbage collector activity that is triggered by it. There can by configuration refresh checks on logging path, inter thread signaling etc.
by garbage collector activity that is triggered by it. There can be configuration refresh checks on logging path, inter thread signaling etc.
To avoid these effects we strive to adhere to the following principles (and document any violations):
-7
View File
@@ -33,12 +33,5 @@
<version>4.1.17</version>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -26,11 +26,10 @@ public class TjahziInitializer {
int bufferSizeBytes,
long logShipperWakeupIntervalMillis,
long shutdownTimeoutMillis,
boolean offHeap,
boolean useDaemonThreads
) {
bufferSizeBytes = findNearestPowerOfTwo(bufferSizeBytes);
ByteBuffer javaBuffer = allocateJavaBuffer(bufferSizeBytes, offHeap);
ByteBuffer javaBuffer = allocateJavaBuffer(bufferSizeBytes);
ManyToOneRingBuffer logBuffer = new ManyToOneRingBuffer(
new UnsafeBuffer(javaBuffer)
@@ -93,17 +92,8 @@ public class TjahziInitializer {
return bufferSize;
}
private ByteBuffer allocateJavaBuffer(
int bufferSize,
boolean offHeap) {
private ByteBuffer allocateJavaBuffer(int bufferSize) {
int totalSize = bufferSize + RingBufferDescriptor.TRAILER_LENGTH;
if (offHeap) {
return ByteBuffer.allocateDirect(totalSize)
.order(ByteOrder.LITTLE_ENDIAN);
}
return ByteBuffer.allocate(totalSize)
.order(ByteOrder.LITTLE_ENDIAN);
return ByteBuffer.allocateDirect(totalSize).order(ByteOrder.LITTLE_ENDIAN);
}
}
@@ -14,7 +14,13 @@ import java.nio.ByteBuffer;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.awaitility.Awaitility.await;
@@ -91,7 +97,6 @@ class HeadersTest {
1024 * 1024,
250,
10_000,
false,
false
);
loggingSystem.start();
@@ -146,7 +151,6 @@ class HeadersTest {
1024 * 1024,
250,
10_000,
false,
false
);
loggingSystem.start();
@@ -203,7 +207,6 @@ class HeadersTest {
1024 * 1024,
250,
10_000,
false,
false
);
loggingSystem.start();
@@ -69,7 +69,6 @@ class LoggingSystemSanityCheckTest {
1024 * 1024,
250,
10_000,
false,
false
);
@@ -126,7 +125,7 @@ class LoggingSystemSanityCheckTest {
.body("data.result[0].stream.server", equalTo("127.0.0.1"))
.body("data.result[0].stream.version", equalTo("0.43"))
.body("data.result[0].stream.level", equalTo("warn"))
.body("data.result[0].values[0]", hasItems("" + (timestamp * 1000_000 +882), "Test"));
.body("data.result[0].values[0]", hasItems("" + (timestamp * 1000_000 + 882), "Test"));
});
}
}
@@ -73,7 +73,6 @@ class LoggingSystemTest {
0,
250,
10_000,
false,
false
);
@@ -159,7 +158,7 @@ class LoggingSystemTest {
index--;
return actualTimestamp == expectedTimestamp
&& actualLogLine.equals(expectedLogLine);
&& actualLogLine.equals(expectedLogLine);
}
}));
});
@@ -14,7 +14,11 @@ import java.nio.ByteBuffer;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.awaitility.Awaitility.await;
@@ -86,7 +90,6 @@ public class ReconnectTest {
1024 * 1024,
250,
10_000,
false,
false
);
loggingSystem.start();
@@ -139,7 +142,6 @@ public class ReconnectTest {
1024 * 1024,
250,
10_000,
false,
false
);
loggingSystem.start();
@@ -82,7 +82,6 @@ class ResourcesCleanupOnCloseTest {
1024 * 1024,
250,
10_000,
false,
false
);
loggingSystem.start();
@@ -146,7 +145,6 @@ class ResourcesCleanupOnCloseTest {
1024 * 1024,
250,
10_000,
false,
true
);
loggingSystem.start();
-6
View File
@@ -327,12 +327,6 @@ to retry indefinitely employing exponential backoff (initial backoff = 250ms, ma
Sets socket read timeout on Loki connection.
#### useOffHeapBuffer (optional, default = true)
Whether Tjahzi should allocate native buffer for `Log buffer` component. We can go into a rabbit hole of divagations
what are the implications of this. Most important in our view is that having 10s or 100s of MB of space taken out of
heap is not very friendly to garbage collector which might have to occasionally copy it around.
#### batchSize (optional, default = 10_2400)
Like
+2 -27
View File
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -40,30 +41,4 @@
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>allocation-profiling</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.java-allocation-instrumenter</groupId>
<artifactId>java-allocation-instrumenter</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
@@ -71,9 +71,6 @@ public class LokiAppenderBuilder<B extends LokiAppenderBuilder<B>> extends Abstr
@PluginBuilderAttribute
private int bufferSizeMegabytes = 32;
@PluginBuilderAttribute
private boolean useOffHeapBuffer = true;
@PluginBuilderAttribute
private String logLevelLabel;
@@ -158,7 +155,6 @@ public class LokiAppenderBuilder<B extends LokiAppenderBuilder<B>> extends Abstr
bufferSizeBytes,
logShipperWakeupIntervalMillis,
TimeUnit.SECONDS.toMillis(shutdownTimeoutSeconds),
isUseOffHeapBuffer(),
useDaemonThreads
);
@@ -280,14 +276,6 @@ public class LokiAppenderBuilder<B extends LokiAppenderBuilder<B>> extends Abstr
this.bufferSizeMegabytes = bufferSizeMegabytes;
}
public boolean isUseOffHeapBuffer() {
return useOffHeapBuffer;
}
public void setUseOffHeapBuffer(boolean useOffHeapBuffer) {
this.useOffHeapBuffer = useOffHeapBuffer;
}
public String getLogLevelLabel() {
return logLevelLabel;
}
-1
View File
@@ -281,7 +281,6 @@ or use Tjahzi optimized efficient, low allocation encoder:
| MaxRetries | 3 | Maximum number of retries to perform when delivering log message to Loki. Log buffer data is delivered in order, one batch after the other, so too much retries will block delivery of subsequent log batches (on the other hand if we need to retry many times then next batches will probably fail too). |
| ConnectTimeoutMillis | 5s | This configures socket connect timeout when connecting to Loki. After unsuccessful connection attempt it will continue to retry indefinitely employing exponential backoff (initial backoff = 250ms, maximum backoff = 30s, multiplier = 3). |
| ReadTimeoutMillis | 60s | Sets socket read timeout on Loki connection. |
| UseOffHeapBuffer | true | Whether Tjahzi should allocate native buffer for `Log buffer` component. We can go into a rabbit hole of divagations what are the implications of this. Most important in our view is that having 10s or 100s of MB of space taken out of heap is not very friendly to garbage collector which might have to occasionally copy it around. |
| BatchSize | 100 KB | Like in [promtail configuration](https://grafana.com/docs/loki/latest/clients/promtail/configuration/) `maximum batch size (in bytes) of logs to accumulate before sending the batch to Loki`. |
| BatchWait | 5s | Like in [promtail configuration](https://grafana.com/docs/loki/latest/clients/promtail/configuration/) `maximum amount of time to wait before sending a batch, even if that batch isn't full`. |
| logShipperWakeupIntervalMillis | 10 | The agent that reads data from log buffer, compresses it and sends to Loki via http is called `LogShipper`. This property controls how often it wakes up to perform its duties. Other properties control how often the data should be sent to Loki (`batchSize`, `batchWait`) this one just control how often to wake up and check for these conditions. In versions before `0.9.17` it was left at default 1ms which caused high CPU usage on some setups. |
-31
View File
@@ -49,35 +49,4 @@
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>allocation-profiling</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>
com.google.code.java-allocation-instrumenter
</groupId>
<artifactId>
java-allocation-instrumenter
</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
@@ -29,7 +29,6 @@ public abstract class LokiAppenderConfigurator extends UnsynchronizedAppenderBas
private int maxRetries = 3;
private int bufferSizeMegabytes = 32;
private boolean useOffHeapBuffer = true;
private String logLevelLabel;
private String loggerNameLabel;
@@ -142,14 +141,6 @@ public abstract class LokiAppenderConfigurator extends UnsynchronizedAppenderBas
this.bufferSizeMegabytes = bufferSizeMegabytes;
}
public boolean isUseOffHeapBuffer() {
return useOffHeapBuffer;
}
public void setUseOffHeapBuffer(boolean useOffHeapBuffer) {
this.useOffHeapBuffer = useOffHeapBuffer;
}
public String getLogLevelLabel() {
return logLevelLabel;
}
@@ -93,7 +93,6 @@ public class LokiAppenderFactory {
bufferSizeBytes,
configurator.getLogShipperWakeupIntervalMillis(),
TimeUnit.SECONDS.toMillis(configurator.getShutdownTimeoutSeconds()),
configurator.isUseOffHeapBuffer(),
configurator.isUseDaemonThreads()
);
}
+32 -2
View File
@@ -357,8 +357,10 @@
<version>3.5.2</version>
<configuration>
<argLine>
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens java.base/sun.net=ALL-UNNAMED
--add-opens
java.base/java.net=ALL-UNNAMED
--add-opens
java.base/sun.net=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
@@ -366,5 +368,33 @@
</pluginManagement>
</build>
</profile>
<profile>
<id>allocation-profiling</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>
com.google.code.java-allocation-instrumenter
</groupId>
<artifactId>
java-allocation-instrumenter
</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>