当前位置: 首页>>代码示例>>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;未经允许,请勿转载。