Java Code Examples for org.elasticsearch.common.breaker.CircuitBreaker#REQUEST

The following examples show how to use org.elasticsearch.common.breaker.CircuitBreaker#REQUEST . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HierarchyCircuitBreakerService.java    From crate with Apache License 2.0 5 votes vote down vote up
private void setRequestBreakerLimit(ByteSizeValue newRequestMax, Double newRequestOverhead) {
    BreakerSettings newRequestSettings = new BreakerSettings(CircuitBreaker.REQUEST, newRequestMax.getBytes(), newRequestOverhead,
            HierarchyCircuitBreakerService.this.requestSettings.getType());
    registerBreaker(newRequestSettings);
    HierarchyCircuitBreakerService.this.requestSettings = newRequestSettings;
    LOGGER.info("Updated breaker settings request: {}", newRequestSettings);
}
 
Example 2
Source File: MockBigArrays.java    From crate with Apache License 2.0 5 votes vote down vote up
private MockBigArrays(PageCacheRecycler recycler, CircuitBreakerService breakerService, boolean checkBreaker) {
    super(recycler, breakerService, CircuitBreaker.REQUEST, checkBreaker);
    this.recycler = recycler;
    this.breakerService = breakerService;
    long seed;
    try {
        seed = SeedUtils.parseSeed(RandomizedContext.current().getRunnerSeedAsString());
    } catch (IllegalStateException e) { // rest tests don't run randomized and have no context
        seed = 0;
    }
    random = new Random(seed);
}
 
Example 3
Source File: HierarchyCircuitBreakerService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Inject
public HierarchyCircuitBreakerService(Settings settings, NodeSettingsService nodeSettingsService) {
    super(settings);

    // This uses the old InternalCircuitBreakerService.CIRCUIT_BREAKER_MAX_BYTES_SETTING
    // setting to keep backwards compatibility with 1.3, it can be safely
    // removed when compatibility with 1.3 is no longer needed
    String compatibilityFielddataLimitDefault = DEFAULT_FIELDDATA_BREAKER_LIMIT;
    ByteSizeValue compatibilityFielddataLimit = settings.getAsMemory(OLD_CIRCUIT_BREAKER_MAX_BYTES_SETTING, null);
    if (compatibilityFielddataLimit != null) {
        compatibilityFielddataLimitDefault = compatibilityFielddataLimit.toString();
    }

    // This uses the old InternalCircuitBreakerService.CIRCUIT_BREAKER_OVERHEAD_SETTING
    // setting to keep backwards compatibility with 1.3, it can be safely
    // removed when compatibility with 1.3 is no longer needed
    double compatibilityFielddataOverheadDefault = DEFAULT_FIELDDATA_OVERHEAD_CONSTANT;
    Double compatibilityFielddataOverhead = settings.getAsDouble(OLD_CIRCUIT_BREAKER_OVERHEAD_SETTING, null);
    if (compatibilityFielddataOverhead != null) {
        compatibilityFielddataOverheadDefault = compatibilityFielddataOverhead;
    }

    this.fielddataSettings = new BreakerSettings(CircuitBreaker.FIELDDATA,
            settings.getAsMemory(FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING, compatibilityFielddataLimitDefault).bytes(),
            settings.getAsDouble(FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING, compatibilityFielddataOverheadDefault),
            CircuitBreaker.Type.parseValue(settings.get(FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING, DEFAULT_BREAKER_TYPE))
    );

    this.requestSettings = new BreakerSettings(CircuitBreaker.REQUEST,
            settings.getAsMemory(REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, DEFAULT_REQUEST_BREAKER_LIMIT).bytes(),
            settings.getAsDouble(REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING, 1.0),
            CircuitBreaker.Type.parseValue(settings.get(REQUEST_CIRCUIT_BREAKER_TYPE_SETTING, DEFAULT_BREAKER_TYPE))
    );

    this.parentSettings = new BreakerSettings(CircuitBreaker.PARENT,
            settings.getAsMemory(TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING, DEFAULT_TOTAL_CIRCUIT_BREAKER_LIMIT).bytes(), 1.0, CircuitBreaker.Type.PARENT);
    if (logger.isTraceEnabled()) {
        logger.trace("parent circuit breaker with settings {}", this.parentSettings);
    }

    registerBreaker(this.requestSettings);
    registerBreaker(this.fielddataSettings);

    nodeSettingsService.addListener(new ApplySettings());
}
 
Example 4
Source File: HierarchyCircuitBreakerService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void onRefreshSettings(Settings settings) {

    // Fielddata settings
    ByteSizeValue newFielddataMax = settings.getAsMemory(FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING, null);
    Double newFielddataOverhead = settings.getAsDouble(FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING, null);
    if (newFielddataMax != null || newFielddataOverhead != null) {
        long newFielddataLimitBytes = newFielddataMax == null ? HierarchyCircuitBreakerService.this.fielddataSettings.getLimit() : newFielddataMax.bytes();
        newFielddataOverhead = newFielddataOverhead == null ? HierarchyCircuitBreakerService.this.fielddataSettings.getOverhead() : newFielddataOverhead;

        BreakerSettings newFielddataSettings = new BreakerSettings(CircuitBreaker.FIELDDATA, newFielddataLimitBytes, newFielddataOverhead,
                HierarchyCircuitBreakerService.this.fielddataSettings.getType());
        registerBreaker(newFielddataSettings);
        HierarchyCircuitBreakerService.this.fielddataSettings = newFielddataSettings;
        logger.info("Updated breaker settings fielddata: {}", newFielddataSettings);
    }

    // Request settings
    ByteSizeValue newRequestMax = settings.getAsMemory(REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, null);
    Double newRequestOverhead = settings.getAsDouble(REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING, null);
    if (newRequestMax != null || newRequestOverhead != null) {
        long newRequestLimitBytes = newRequestMax == null ? HierarchyCircuitBreakerService.this.requestSettings.getLimit() : newRequestMax.bytes();
        newRequestOverhead = newRequestOverhead == null ? HierarchyCircuitBreakerService.this.requestSettings.getOverhead() : newRequestOverhead;

        BreakerSettings newRequestSettings = new BreakerSettings(CircuitBreaker.REQUEST, newRequestLimitBytes, newRequestOverhead,
                HierarchyCircuitBreakerService.this.requestSettings.getType());
        registerBreaker(newRequestSettings);
        HierarchyCircuitBreakerService.this.requestSettings = newRequestSettings;
        logger.info("Updated breaker settings request: {}", newRequestSettings);
    }

    // Parent settings
    long oldParentMax = HierarchyCircuitBreakerService.this.parentSettings.getLimit();
    ByteSizeValue newParentMax = settings.getAsMemory(TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING, null);
    if (newParentMax != null && (newParentMax.bytes() != oldParentMax)) {
        BreakerSettings newParentSettings = new BreakerSettings(CircuitBreaker.PARENT, newParentMax.bytes(), 1.0, CircuitBreaker.Type.PARENT);
        validateSettings(new BreakerSettings[]{newParentSettings});
        HierarchyCircuitBreakerService.this.parentSettings = newParentSettings;
        logger.info("Updated breaker settings parent: {}", newParentSettings);
    }
}
 
Example 5
Source File: HierarchyCircuitBreakerService.java    From crate with Apache License 2.0 4 votes vote down vote up
public HierarchyCircuitBreakerService(Settings settings, ClusterSettings clusterSettings) {
    this.fielddataSettings = new BreakerSettings(CircuitBreaker.FIELDDATA,
            FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING.get(settings).getBytes(),
            FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING.get(settings),
            FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING.get(settings)
    );

    this.inFlightRequestsSettings = new BreakerSettings(CircuitBreaker.IN_FLIGHT_REQUESTS,
            IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.get(settings).getBytes(),
            IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_OVERHEAD_SETTING.get(settings),
            IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_TYPE_SETTING.get(settings)
    );

    this.requestSettings = new BreakerSettings(CircuitBreaker.REQUEST,
            REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.get(settings).getBytes(),
            REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING.get(settings),
            REQUEST_CIRCUIT_BREAKER_TYPE_SETTING.get(settings)
    );

    this.accountingSettings = new BreakerSettings(CircuitBreaker.ACCOUNTING,
            ACCOUNTING_CIRCUIT_BREAKER_LIMIT_SETTING.get(settings).getBytes(),
            ACCOUNTING_CIRCUIT_BREAKER_OVERHEAD_SETTING.get(settings),
            ACCOUNTING_CIRCUIT_BREAKER_TYPE_SETTING.get(settings)
    );

    this.parentSettings = new BreakerSettings(CircuitBreaker.PARENT,
            TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING.get(settings).getBytes(), 1.0,
            CircuitBreaker.Type.PARENT);

    queryBreakerSettings = new BreakerSettings(QUERY,
        QUERY_CIRCUIT_BREAKER_LIMIT_SETTING.setting().get(settings).getBytes(),
        QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING.setting().get(settings),
        CircuitBreaker.Type.MEMORY
    );

    logJobsBreakerSettings = new BreakerSettings(JOBS_LOG,
        JOBS_LOG_CIRCUIT_BREAKER_LIMIT_SETTING.setting().get(settings).getBytes(),
        JOBS_LOG_CIRCUIT_BREAKER_OVERHEAD_SETTING.setting().get(settings),
        CircuitBreaker.Type.MEMORY);

    logOperationsBreakerSettings = new BreakerSettings(OPERATIONS_LOG,
        OPERATIONS_LOG_CIRCUIT_BREAKER_LIMIT_SETTING.setting().get(settings).getBytes(),
        OPERATIONS_LOG_CIRCUIT_BREAKER_OVERHEAD_SETTING.setting().get(settings),
        CircuitBreaker.Type.MEMORY);

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("parent circuit breaker with settings {}", this.parentSettings);
    }

    registerBreaker(this.requestSettings);
    registerBreaker(this.fielddataSettings);
    registerBreaker(this.inFlightRequestsSettings);
    registerBreaker(this.accountingSettings);
    registerBreaker(this.queryBreakerSettings);
    registerBreaker(this.logJobsBreakerSettings);
    registerBreaker(this.logOperationsBreakerSettings);

    clusterSettings.addSettingsUpdateConsumer(TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING, this::setTotalCircuitBreakerLimit, this::validateTotalCircuitBreakerLimit);
    clusterSettings.addSettingsUpdateConsumer(FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING, FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING, this::setFieldDataBreakerLimit);
    clusterSettings.addSettingsUpdateConsumer(IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING, IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_OVERHEAD_SETTING, this::setInFlightRequestsBreakerLimit);
    clusterSettings.addSettingsUpdateConsumer(REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING, this::setRequestBreakerLimit);
    clusterSettings.addSettingsUpdateConsumer(ACCOUNTING_CIRCUIT_BREAKER_LIMIT_SETTING, ACCOUNTING_CIRCUIT_BREAKER_OVERHEAD_SETTING, this::setAccountingBreakerLimit);
    clusterSettings.addSettingsUpdateConsumer(QUERY_CIRCUIT_BREAKER_LIMIT_SETTING.setting(), QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING.setting(),
        (newLimit, newOverhead) ->
            setBreakerLimit(queryBreakerSettings, QUERY, s -> this.queryBreakerSettings = s, newLimit, newOverhead));
    clusterSettings.addSettingsUpdateConsumer(JOBS_LOG_CIRCUIT_BREAKER_LIMIT_SETTING.setting(),
        (newLimit) ->
            setBreakerLimit(logJobsBreakerSettings, JOBS_LOG, s -> this.logJobsBreakerSettings = s, newLimit, null));
    clusterSettings.addSettingsUpdateConsumer(OPERATIONS_LOG_CIRCUIT_BREAKER_LIMIT_SETTING.setting(),
        (newLimit) ->
            setBreakerLimit(logOperationsBreakerSettings, OPERATIONS_LOG, s -> this.logOperationsBreakerSettings = s, newLimit, null));
}
 
Example 6
Source File: Node.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@link BigArrays} instance used for this node.
 * This method can be overwritten by subclasses to change their {@link BigArrays} implementation for instance for testing
 */
BigArrays createBigArrays(PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService) {
    return new BigArrays(pageCacheRecycler, circuitBreakerService, CircuitBreaker.REQUEST);
}