java-dogstatsd-client icon indicating copy to clipboard operation
java-dogstatsd-client copied to clipboard

CPU regression with NonBlockingStatsDClient

Open elenatomlinson opened this issue 4 years ago • 1 comments

Hi there,

We recently migrated from NonBlockingStatsDClient.java to DataDog's NonBlockingStatsDClient.java. We see significant increase of cpu usage, proportional to number of instances of the client. e.g. single application pod cpu usage in millicores increased from 2 to 10 after migration, then from 10 to 29 after instantiating 3x the number of clients during experimentation.

elenatomlinson avatar Jan 13 '21 01:01 elenatomlinson

it seems that the sample rate is out of use when aggregation is enabled. the usage of cpu and memory may increase when monitoring massive messages.

https://github.com/DataDog/java-dogstatsd-client/blob/master/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java#L1191-L1209

    private void send(String aspect, final long value, Message.Type type, double sampleRate, String[] tags) {
        if (statsDProcessor.getAggregator().getFlushInterval() != 0 && !Double.isNaN(sampleRate)) {
            switch (type) {
                case COUNT:
                    sampleRate = Double.NaN; // <-- reset sampleRate to NaN
                    break;
                default:
                    break;
            }
        }

        if (Double.isNaN(sampleRate) || !isInvalidSample(sampleRate)) {

            sendMetric(new StatsDMessage<Long>(aspect, type, value, sampleRate, tags) {
                @Override protected void writeValue(StringBuilder builder) {
                    builder.append(this.value);
                }
            });
        }
    }

conderls avatar Jan 18 '21 11:01 conderls