protected void recordWaitTime(long timeNs) {
        this.waitTime.record(timeNs, time.milliseconds());
    }
Allocate a buffer of the given size. This method blocks if there is not enough memory and the buffer pool
is configured with blocking mode.

@param size The buffer size to allocate in bytes
@param maxTimeToBlockMs The maximum time in milliseconds to block for buffer memory to be available
@return The buffer
@throws InterruptedException If the thread is interrupted while blocked
@throws IllegalArgumentException if size is larger than the total memory controlled by the pool (and hence we would block
        forever)
clients/src/main/java/org/apache/kafka/clients/producer/internals/BufferPool.java