Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class DDAgentApi {
private static final String TRACES_ENDPOINT_V4 = "v0.4/traces";
private static final long MILLISECONDS_BETWEEN_ERROR_LOG = TimeUnit.MINUTES.toMillis(5);

// limiting the size this optimisation applies to decreases the likelihood
// that the MessagePacker will allocate a byte[] during UTF-8 encoding,
// and restricts the optimisation to very small strings which may scalarise
private static final MessagePack.PackerConfig MESSAGE_PACKER_CONFIG =
MessagePack.DEFAULT_PACKER_CONFIG.withSmallStringOptimizationThreshold(16);
Comment thread
richardstartin marked this conversation as resolved.
Comment thread
bantonsson marked this conversation as resolved.

private final List<DDAgentResponseListener> responseListeners = new ArrayList<>();

private volatile long nextAllowedLogTime = 0;
Expand Down Expand Up @@ -106,7 +112,7 @@ Response sendTraces(final List<List<DDSpan>> traces) {
byte[] serializeTrace(final List<DDSpan> trace) throws IOException {
// TODO: reuse byte array buffer
final ArrayBufferOutput output = new ArrayBufferOutput();
final MessagePacker packer = MessagePack.newDefaultPacker(output);
final MessagePacker packer = MESSAGE_PACKER_CONFIG.newPacker(output);
MSGPACK_WRITER.writeTrace(trace, packer);
packer.flush();
return output.toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,9 @@ class DDAgentWriterTest extends DDSpecification {

static int calculateSize(List<DDSpan> trace) {
def buffer = new ArrayBufferOutput()
def packer = MessagePack.newDefaultPacker(buffer)
def packer = MessagePack.DEFAULT_PACKER_CONFIG
.withSmallStringOptimizationThreshold(16)
.newPacker(buffer)
MSGPACK_WRITER.writeTrace(trace, packer)
packer.flush()
return buffer.size
Expand Down