/** * Flush the {@code flushBuffer} to the breaker, incrementing the total * bytes and resetting the buffer. */ public void flush() { breaker.addEstimateBytesAndMaybeBreak(this.flushBuffer, this.fieldName); this.totalBytes += this.flushBuffer; this.flushBuffer = 0; }
/** * Increment or decrement the number of bytes that have been allocated to service * this request and potentially trigger a {@link CircuitBreakingException}. The * number of bytes allocated is automatically decremented with the circuit breaker * service on closure of this aggregator. * If memory has been returned, decrement it without tripping the breaker. * For performance reasons subclasses should not call this millions of times * each with small increments and instead batch up into larger allocations. * * @param bytes the number of bytes to register or negative to deregister the bytes * @return the cumulative size in bytes allocated by this aggregator to service this request */ protected long addRequestCircuitBreakerBytes(long bytes) { // Only use the potential to circuit break if bytes are being incremented if (bytes > 0) { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addEstimateBytesAndMaybeBreak(bytes, "<agg [" + name + "]>"); } else { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addWithoutBreaking(bytes); } this.requestBytesUsed += bytes; return requestBytesUsed; } /**
breaker.addEstimateBytesAndMaybeBreak(delta, "<reused_arrays>"); } catch (CircuitBreakingException e) { if (isDataAlreadyCreated) {
iterator = new RamAccountingTermsEnum(iterator, breaker, this, this.fieldName); } else { breaker.addEstimateBytesAndMaybeBreak(estimatedBytes, fieldName);
inFlightRequestsBreaker(circuitBreakerService).addEstimateBytesAndMaybeBreak(contentLength, "<http_request>"); } else { inFlightRequestsBreaker(circuitBreakerService).addWithoutBreaking(contentLength);
/** * Flush the {@code flushBuffer} to the breaker, incrementing the total * bytes and resetting the buffer. */ public void flush() { breaker.addEstimateBytesAndMaybeBreak(this.flushBuffer, this.fieldName); this.totalBytes += this.flushBuffer; this.flushBuffer = 0; }
/** * Flush the {@code flushBuffer} to the breaker, incrementing the total * bytes and resetting the buffer. */ public void flush() { breaker.addEstimateBytesAndMaybeBreak(this.flushBuffer, this.fieldName); this.totalBytes += this.flushBuffer; this.flushBuffer = 0; }
/** * Flush the {@code flushBuffer} to the breaker, incrementing the total * bytes and resetting the buffer. */ public void flush() { breaker.addEstimateBytesAndMaybeBreak(this.flushBuffer, this.fieldName); this.totalBytes += this.flushBuffer; this.flushBuffer = 0; }
/** * Flush the {@code flushBuffer} to the breaker, incrementing the total * bytes and resetting the buffer. */ public void flush() { breaker.addEstimateBytesAndMaybeBreak(this.flushBuffer, this.fieldName); this.totalBytes += this.flushBuffer; this.flushBuffer = 0; }
getInFlightRequestBreaker().addEstimateBytesAndMaybeBreak(messageLengthBytes, "<transport_request>"); } else { getInFlightRequestBreaker().addWithoutBreaking(messageLengthBytes);
@Override protected BitArray createBitArray(long numBits) { int memSize = Ints.checkedCast(LongMath.divide(numBits, 64, RoundingMode.CEILING)) * 8; // Adjust the breaker with the new memory size breaker.addEstimateBytesAndMaybeBreak(memSize, "<terms_set>"); try { return new BitArray(numBits); } catch (OutOfMemoryError e) { // Ensure no change is done if we hit an OOM. breaker.addWithoutBreaking(-memSize); throw e; } }
@Override protected void allocateBuffers(int arraySize) { long newMemSize = (arraySize + 1) * 8l; // array size + emptyElementSlot long oldMemSize = keys == null ? 0 : keys.length * 8l; // Adjust the breaker with the new memory size breaker.addEstimateBytesAndMaybeBreak(newMemSize, "<terms_set>"); try { // Allocate the new buffer super.allocateBuffers(arraySize); // Adjust the breaker by removing old memory size breaker.addWithoutBreaking(-oldMemSize); } catch (BufferAllocationException e) { // If the allocation failed, remove breaker.addWithoutBreaking(-newMemSize); throw e; } }
@Override protected void allocateBuffers(int arraySize) { long newMemSize = (arraySize + 1) * 4l; // array size + emtpyElementSlot long oldMemSize = keys == null ? 0 : keys.length * 4l; // Adjust the breaker with the new memory size breaker.addEstimateBytesAndMaybeBreak(newMemSize, "<terms_set>"); try { // Allocate the new buffer super.allocateBuffers(arraySize); // Adjust the breaker by removing old memory size breaker.addWithoutBreaking(-oldMemSize); } catch (BufferAllocationException e) { // If the allocation failed, remove breaker.addWithoutBreaking(-newMemSize); } }
/** * Increment or decrement the number of bytes that have been allocated to service * this request and potentially trigger a {@link CircuitBreakingException}. The * number of bytes allocated is automatically decremented with the circuit breaker * service on closure of this aggregator. * If memory has been returned, decrement it without tripping the breaker. * For performance reasons subclasses should not call this millions of times * each with small increments and instead batch up into larger allocations. * * @param bytes the number of bytes to register or negative to deregister the bytes * @return the cumulative size in bytes allocated by this aggregator to service this request */ protected long addRequestCircuitBreakerBytes(long bytes) { // Only use the potential to circuit break if bytes are being incremented if (bytes > 0) { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addEstimateBytesAndMaybeBreak(bytes, "<agg [" + name + "]>"); } else { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addWithoutBreaking(bytes); } this.requestBytesUsed += bytes; return requestBytesUsed; } /**
/** * Increment or decrement the number of bytes that have been allocated to service * this request and potentially trigger a {@link CircuitBreakingException}. The * number of bytes allocated is automatically decremented with the circuit breaker * service on closure of this aggregator. * If memory has been returned, decrement it without tripping the breaker. * For performance reasons subclasses should not call this millions of times * each with small increments and instead batch up into larger allocations. * * @param bytes the number of bytes to register or negative to deregister the bytes * @return the cumulative size in bytes allocated by this aggregator to service this request */ protected long addRequestCircuitBreakerBytes(long bytes) { // Only use the potential to circuit break if bytes are being incremented if (bytes > 0) { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addEstimateBytesAndMaybeBreak(bytes, "<agg [" + name + "]>"); } else { this.breakerService .getBreaker(CircuitBreaker.REQUEST) .addWithoutBreaking(bytes); } this.requestBytesUsed += bytes; return requestBytesUsed; } /**
breaker.addEstimateBytesAndMaybeBreak(delta, "<reused_arrays>"); } catch (CircuitBreakingException e) { if (isDataAlreadyCreated) {
breaker.addEstimateBytesAndMaybeBreak(delta, "<reused_arrays>"); } catch (CircuitBreakingException e) { if (isDataAlreadyCreated) {
iterator = new RamAccountingTermsEnum(iterator, breaker, this, this.fieldName); } else { breaker.addEstimateBytesAndMaybeBreak(estimatedBytes, fieldName);
public void internalDispatchRequest(final RestRequest request, final RestChannel channel) { String rawPath = request.rawPath(); if (rawPath.startsWith("/_plugin/")) { RestFilterChain filterChain = restController.filterChain(pluginSiteFilter); filterChain.continueProcessing(request, channel); return; } else if (rawPath.equals("/favicon.ico")) { handleFavicon(request, channel); return; } RestChannel responseChannel = channel; try { int contentLength = request.content().length(); if (restController.canTripCircuitBreaker(request)) { inFlightRequestsBreaker(circuitBreakerService).addEstimateBytesAndMaybeBreak(contentLength, "<http_request>"); } else { inFlightRequestsBreaker(circuitBreakerService).addWithoutBreaking(contentLength); } // iff we could reserve bytes for the request we need to send the response also over this channel responseChannel = new ResourceHandlingHttpChannel(channel, circuitBreakerService); restController.dispatchRequest(request, responseChannel); } catch (Throwable t) { restController.sendErrorResponse(request, responseChannel, t); } }
@Override public void readFrom(StreamInput in) throws IOException { // Decode flag this.setIsPruned(in.readBoolean()); // Decode bloom filter int numberOfHashFunctions = in.readVInt(); int hashType = in.readVInt(); int numLongs = in.readVInt(); // Adjust breaker long memSize = numLongs * 8; breaker.addEstimateBytesAndMaybeBreak(memSize, "<terms_set>"); try { long[] data = new long[numLongs]; for (int i = 0; i < numLongs; i++) { data[i] = in.readLong(); } set = new CircuitBreakerLongBloomFilter(new LongBloomFilter.BitArray(data), numberOfHashFunctions, LongBloomFilter.Hashing.fromType(hashType)); } catch (OutOfMemoryError e) { // Ensure no change is done if we hit an OOM. breaker.addWithoutBreaking(-memSize); throw e; } }