當前位置: 首頁>>代碼示例>>Java>>正文


Java BreakerSettings類代碼示例

本文整理匯總了Java中org.elasticsearch.indices.breaker.BreakerSettings的典型用法代碼示例。如果您正苦於以下問題:Java BreakerSettings類的具體用法?Java BreakerSettings怎麽用?Java BreakerSettings使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BreakerSettings類屬於org.elasticsearch.indices.breaker包,在下文中一共展示了BreakerSettings類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ChildMemoryCircuitBreaker

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
/**
 * Create a circuit breaker that will break if the number of estimated
 * bytes grows above the limit. All estimations will be multiplied by
 * the given overheadConstant. Uses the given oldBreaker to initialize
 * the starting offset.
 * @param settings settings to configure this breaker
 * @param parent parent circuit breaker service to delegate tripped breakers to
 * @param name the name of the breaker
 * @param oldBreaker the previous circuit breaker to inherit the used value from (starting offset)
 */
public ChildMemoryCircuitBreaker(BreakerSettings settings, ChildMemoryCircuitBreaker oldBreaker,
                                 Logger logger, HierarchyCircuitBreakerService parent, String name) {
    this.name = name;
    this.settings = settings;
    this.memoryBytesLimit = settings.getLimit();
    this.overheadConstant = settings.getOverhead();
    if (oldBreaker == null) {
        this.used = new AtomicLong(0);
        this.trippedCount = new AtomicLong(0);
    } else {
        this.used = oldBreaker.used;
        this.trippedCount = oldBreaker.trippedCount;
    }
    this.logger = logger;
    if (logger.isTraceEnabled()) {
        logger.trace("creating ChildCircuitBreaker with settings {}", this.settings);
    }
    this.parent = parent;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:ChildMemoryCircuitBreaker.java

示例2: CrateCircuitBreakerService

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
@Inject
public CrateCircuitBreakerService(Settings settings,
                                  NodeSettingsService nodeSettingsService,
                                  CircuitBreakerService esCircuitBreakerService) {
    super(settings);
    this.esCircuitBreakerService = esCircuitBreakerService;

    long memoryLimit = settings.getAsMemory(
            QUERY_CIRCUIT_BREAKER_LIMIT_SETTING,
            DEFAULT_QUERY_CIRCUIT_BREAKER_LIMIT).bytes();
    double overhead = settings.getAsDouble(
            QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING,
            DEFAULT_QUERY_CIRCUIT_BREAKER_OVERHEAD_CONSTANT);

    queryBreakerSettings = new BreakerSettings(QUERY, memoryLimit, overhead,
            CircuitBreaker.Type.parseValue(
                    settings.get(QUERY_CIRCUIT_BREAKER_TYPE_SETTING,
                    DEFAULT_QUERY_CIRCUIT_BREAKER_TYPE)));

    registerBreaker(queryBreakerSettings);
    nodeSettingsService.addListener(new ApplySettings());
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:23,代碼來源:CrateCircuitBreakerService.java

示例3: onRefreshSettings

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
@Override
public void onRefreshSettings(Settings settings) {

    // Query breaker settings
    long newQueryMax = settings.getAsMemory(
            QUERY_CIRCUIT_BREAKER_LIMIT_SETTING,
            CrateCircuitBreakerService.this.settings.getAsMemory(
                    QUERY_CIRCUIT_BREAKER_LIMIT_SETTING,
                    DEFAULT_QUERY_CIRCUIT_BREAKER_LIMIT
            ).toString()).bytes();
    Double newQueryOverhead = settings.getAsDouble(
            QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING,
            CrateCircuitBreakerService.this.settings.getAsDouble(
                    QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING,
                    DEFAULT_QUERY_CIRCUIT_BREAKER_OVERHEAD_CONSTANT
            ));
    if (newQueryMax != CrateCircuitBreakerService.this.queryBreakerSettings.getLimit()
            || newQueryOverhead != CrateCircuitBreakerService.this.queryBreakerSettings.getOverhead()) {

        BreakerSettings newQuerySettings = new BreakerSettings(
                QUERY, newQueryMax, newQueryOverhead,
                CrateCircuitBreakerService.this.queryBreakerSettings.getType());
        registerBreaker(newQuerySettings);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:26,代碼來源:CrateCircuitBreakerService.java

示例4: ChildMemoryCircuitBreaker

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
/**
 * Create a circuit breaker that will break if the number of estimated
 * bytes grows above the limit. All estimations will be multiplied by
 * the given overheadConstant. Uses the given oldBreaker to initialize
 * the starting offset.
 * @param settings settings to configure this breaker
 * @param parent parent circuit breaker service to delegate tripped breakers to
 * @param name the name of the breaker
 * @param oldBreaker the previous circuit breaker to inherit the used value from (starting offset)
 */
public ChildMemoryCircuitBreaker(BreakerSettings settings, ChildMemoryCircuitBreaker oldBreaker,
                                 ESLogger logger, HierarchyCircuitBreakerService parent, String name) {
    this.name = name;
    this.settings = settings;
    this.memoryBytesLimit = settings.getLimit();
    this.overheadConstant = settings.getOverhead();
    if (oldBreaker == null) {
        this.used = new AtomicLong(0);
        this.trippedCount = new AtomicLong(0);
    } else {
        this.used = oldBreaker.used;
        this.trippedCount = oldBreaker.trippedCount;
    }
    this.logger = logger;
    if (logger.isTraceEnabled()) {
        logger.trace("creating ChildCircuitBreaker with settings {}", this.settings);
    }
    this.parent = parent;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:30,代碼來源:ChildMemoryCircuitBreaker.java

示例5: testCustomCircuitBreakerRegistration

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
public void testCustomCircuitBreakerRegistration() throws Exception {
    Iterable<CircuitBreakerService> serviceIter = internalCluster().getInstances(CircuitBreakerService.class);

    final String breakerName = "customBreaker";
    BreakerSettings breakerSettings = new BreakerSettings(breakerName, 8, 1.03);
    CircuitBreaker breaker = null;

    for (CircuitBreakerService s : serviceIter) {
        s.registerBreaker(breakerSettings);
        breaker = s.getBreaker(breakerSettings.getName());
    }

    if (breaker != null) {
        try {
            breaker.addEstimateBytesAndMaybeBreak(16, "test");
        } catch (CircuitBreakingException e) {
            // ignore, we forced a circuit break
        }
    }

    NodesStatsResponse stats = client().admin().cluster().prepareNodesStats().clear().setBreaker(true).get();
    int breaks = 0;
    for (NodeStats stat : stats.getNodes()) {
        CircuitBreakerStats breakerStats = stat.getBreaker().getStats(breakerName);
        breaks += breakerStats.getTrippedCount();
    }
    assertThat(breaks, greaterThanOrEqualTo(1));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:29,代碼來源:CircuitBreakerServiceIT.java

示例6: testBreakerSettingsValidationNegativeOverhead

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
public void testBreakerSettingsValidationNegativeOverhead() {
    // parent: {:limit 70}, fd: {:limit 50}, request: {:limit 20}
    BreakerSettings fd = new BreakerSettings(CircuitBreaker.FIELDDATA, pctBytes("50%"), -0.1);
    BreakerSettings request = new BreakerSettings(CircuitBreaker.REQUEST, pctBytes("20%"), 1.0);
    try {
        HierarchyCircuitBreakerService.validateSettings(new BreakerSettings[]{fd, request});
        fail("settings are invalid but validate settings did not throw an exception");
    } catch (Exception e) {
        assertThat("Incorrect message: " + e.getMessage(),
                e.getMessage().contains("must be non-negative"), equalTo(true));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:CircuitBreakerUnitTests.java

示例7: testRegisterCustomBreaker

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
public void testRegisterCustomBreaker() throws Exception {
    CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    String customName = "custom";
    BreakerSettings settings = new BreakerSettings(customName, 20, 1.0);
    service.registerBreaker(settings);

    CircuitBreaker breaker = service.getBreaker(customName);
    assertThat(breaker, notNullValue());
    assertThat(breaker, instanceOf(CircuitBreaker.class));
    assertThat(breaker.getName(), is(customName));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:12,代碼來源:CircuitBreakerUnitTests.java

示例8: testThreadedUpdatesToChildBreaker

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
public void testThreadedUpdatesToChildBreaker() throws Exception {
    final int NUM_THREADS = scaledRandomIntBetween(3, 15);
    final int BYTES_PER_THREAD = scaledRandomIntBetween(500, 4500);
    final Thread[] threads = new Thread[NUM_THREADS];
    final AtomicBoolean tripped = new AtomicBoolean(false);
    final AtomicReference<Throwable> lastException = new AtomicReference<>(null);

    final AtomicReference<ChildMemoryCircuitBreaker> breakerRef = new AtomicReference<>(null);
    final CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) {

        @Override
        public CircuitBreaker getBreaker(String name) {
            return breakerRef.get();
        }

        @Override
        public void checkParentLimit(String label) throws CircuitBreakingException {
            // never trip
        }
    };
    final BreakerSettings settings = new BreakerSettings(CircuitBreaker.REQUEST, (BYTES_PER_THREAD * NUM_THREADS) - 1, 1.0);
    final ChildMemoryCircuitBreaker breaker = new ChildMemoryCircuitBreaker(settings, logger,
            (HierarchyCircuitBreakerService)service, CircuitBreaker.REQUEST);
    breakerRef.set(breaker);

    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < BYTES_PER_THREAD; j++) {
                    try {
                        breaker.addEstimateBytesAndMaybeBreak(1L, "test");
                    } catch (CircuitBreakingException e) {
                        if (tripped.get()) {
                            assertThat("tripped too many times", true, equalTo(false));
                        } else {
                            assertThat(tripped.compareAndSet(false, true), equalTo(true));
                        }
                    } catch (Exception e) {
                        lastException.set(e);
                    }
                }
            }
        });

        threads[i].start();
    }

    for (Thread t : threads) {
        t.join();
    }

    assertThat("no other exceptions were thrown", lastException.get(), equalTo(null));
    assertThat("breaker was tripped", tripped.get(), equalTo(true));
    assertThat("breaker was tripped at least once", breaker.getTrippedCount(), greaterThanOrEqualTo(1L));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:57,代碼來源:MemoryCircuitBreakerTests.java

示例9: registerBreaker

import org.elasticsearch.indices.breaker.BreakerSettings; //導入依賴的package包/類
@Override
public void registerBreaker(BreakerSettings breakerSettings) {
    esCircuitBreakerService.registerBreaker(breakerSettings);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:5,代碼來源:CrateCircuitBreakerService.java


注:本文中的org.elasticsearch.indices.breaker.BreakerSettings類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。