continue; if (size + first.estimatedSizeInBytes() > maxSize && !ready.isEmpty()) {
public void updateProduceRequestMetrics(Map<Integer, List<ProducerBatch>> batches) { long now = time.milliseconds(); for (List<ProducerBatch> nodeBatch : batches.values()) { int records = 0; for (ProducerBatch batch : nodeBatch) { // register all per-topic metrics at once String topic = batch.topicPartition.topic(); maybeRegisterTopicMetrics(topic); // per-topic record send rate String topicRecordsCountName = "topic." + topic + ".records-per-batch"; Sensor topicRecordCount = Utils.notNull(this.metrics.getSensor(topicRecordsCountName)); topicRecordCount.record(batch.recordCount); // per-topic bytes send rate String topicByteRateName = "topic." + topic + ".bytes"; Sensor topicByteRate = Utils.notNull(this.metrics.getSensor(topicByteRateName)); topicByteRate.record(batch.estimatedSizeInBytes()); // per-topic compression rate String topicCompressionRateName = "topic." + topic + ".compression-rate"; Sensor topicCompressionRate = Utils.notNull(this.metrics.getSensor(topicCompressionRateName)); topicCompressionRate.record(batch.compressionRatio()); // global metrics this.batchSizeSensor.record(batch.estimatedSizeInBytes(), now); this.queueTimeSensor.record(batch.queueTimeMs(), now); this.compressionRateSensor.record(batch.compressionRatio()); this.maxRecordSizeSensor.record(batch.maxRecordSize, now); records += batch.recordCount; } this.recordsPerRequestSensor.record(records, now); } }
private BatchDrainedResult completeOrSplitBatches(RecordAccumulator accum, int batchSize) { int numSplit = 0; int numBatches = 0; boolean batchDrained; do { batchDrained = false; RecordAccumulator.ReadyCheckResult result = accum.ready(cluster, time.milliseconds()); Map<Integer, List<ProducerBatch>> batches = accum.drain(cluster, result.readyNodes, Integer.MAX_VALUE, time.milliseconds()); for (List<ProducerBatch> batchList : batches.values()) { for (ProducerBatch batch : batchList) { batchDrained = true; numBatches++; if (batch.estimatedSizeInBytes() > batchSize + DefaultRecordBatch.RECORD_BATCH_OVERHEAD) { accum.splitAndReenqueue(batch); // release the resource of the original big batch. numSplit++; } else { batch.done(0L, 0L, null); } accum.deallocate(batch); } } } while (batchDrained); return new BatchDrainedResult(numSplit, numBatches); }