Search in sources :

Example 1 with NioEventLoopGroup

use of com.couchbase.client.deps.io.netty.channel.nio.NioEventLoopGroup in project YCSB by brianfrankcooper.

the class BackoffSelectStrategy method init.

@Override
public void init() throws DBException {
    Properties props = getProperties();
    host = props.getProperty("couchbase.host", "127.0.0.1");
    bucketName = props.getProperty("couchbase.bucket", "default");
    String bucketPassword = props.getProperty("couchbase.password", "");
    upsert = props.getProperty("couchbase.upsert", "false").equals("true");
    persistTo = parsePersistTo(props.getProperty("couchbase.persistTo", "0"));
    replicateTo = parseReplicateTo(props.getProperty("couchbase.replicateTo", "0"));
    syncMutResponse = props.getProperty("couchbase.syncMutationResponse", "true").equals("true");
    adhoc = props.getProperty("couchbase.adhoc", "false").equals("true");
    kv = props.getProperty("couchbase.kv", "true").equals("true");
    maxParallelism = Integer.parseInt(props.getProperty("couchbase.maxParallelism", "1"));
    kvEndpoints = Integer.parseInt(props.getProperty("couchbase.kvEndpoints", "1"));
    queryEndpoints = Integer.parseInt(props.getProperty("couchbase.queryEndpoints", "1"));
    epoll = props.getProperty("couchbase.epoll", "false").equals("true");
    boost = Integer.parseInt(props.getProperty("couchbase.boost", "3"));
    networkMetricsInterval = Integer.parseInt(props.getProperty("couchbase.networkMetricsInterval", "0"));
    runtimeMetricsInterval = Integer.parseInt(props.getProperty("couchbase.runtimeMetricsInterval", "0"));
    documentExpiry = Integer.parseInt(props.getProperty("couchbase.documentExpiry", "0"));
    scanAllQuery = "SELECT RAW meta().id FROM `" + bucketName + "` WHERE meta().id >= '$1' ORDER BY meta().id LIMIT $2";
    try {
        synchronized (INIT_COORDINATOR) {
            if (env == null) {
                LatencyMetricsCollectorConfig latencyConfig = networkMetricsInterval <= 0 ? DefaultLatencyMetricsCollectorConfig.disabled() : DefaultLatencyMetricsCollectorConfig.builder().emitFrequency(networkMetricsInterval).emitFrequencyUnit(TimeUnit.SECONDS).build();
                MetricsCollectorConfig runtimeConfig = runtimeMetricsInterval <= 0 ? DefaultMetricsCollectorConfig.disabled() : DefaultMetricsCollectorConfig.create(runtimeMetricsInterval, TimeUnit.SECONDS);
                DefaultCouchbaseEnvironment.Builder builder = DefaultCouchbaseEnvironment.builder().queryEndpoints(queryEndpoints).callbacksOnIoPool(true).runtimeMetricsCollectorConfig(runtimeConfig).networkLatencyMetricsCollectorConfig(latencyConfig).socketConnectTimeout(// 10 secs socket connect timeout
                10000).connectTimeout(// 30 secs overall bucket open timeout
                30000).kvTimeout(// 10 instead of 2.5s for KV ops
                10000).kvEndpoints(kvEndpoints);
                // Tune boosting and epoll based on settings
                SelectStrategyFactory factory = boost > 0 ? new BackoffSelectStrategyFactory() : DefaultSelectStrategyFactory.INSTANCE;
                int poolSize = boost > 0 ? boost : Integer.parseInt(System.getProperty("com.couchbase.ioPoolSize", Integer.toString(DefaultCoreEnvironment.IO_POOL_SIZE)));
                ThreadFactory threadFactory = new DefaultThreadFactory("cb-io", true);
                EventLoopGroup group = epoll ? new EpollEventLoopGroup(poolSize, threadFactory, factory) : new NioEventLoopGroup(poolSize, threadFactory, SelectorProvider.provider(), factory);
                builder.ioPool(group, new IoPoolShutdownHook(group));
                env = builder.build();
                logParams();
            }
        }
        cluster = CouchbaseCluster.create(env, host);
        bucket = cluster.openBucket(bucketName, bucketPassword);
        kvTimeout = env.kvTimeout();
    } catch (Exception ex) {
        throw new DBException("Could not connect to Couchbase Bucket.", ex);
    }
    if (!kv && !syncMutResponse) {
        throw new DBException("Not waiting for N1QL responses on mutations not yet implemented.");
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) DefaultThreadFactory(com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory) DBException(com.yahoo.ycsb.DBException) DefaultLatencyMetricsCollectorConfig(com.couchbase.client.core.metrics.DefaultLatencyMetricsCollectorConfig) LatencyMetricsCollectorConfig(com.couchbase.client.core.metrics.LatencyMetricsCollectorConfig) TemporaryFailureException(com.couchbase.client.java.error.TemporaryFailureException) DBException(com.yahoo.ycsb.DBException) DefaultThreadFactory(com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory) DefaultSelectStrategyFactory(com.couchbase.client.deps.io.netty.channel.DefaultSelectStrategyFactory) SelectStrategyFactory(com.couchbase.client.deps.io.netty.channel.SelectStrategyFactory) EventLoopGroup(com.couchbase.client.deps.io.netty.channel.EventLoopGroup) NioEventLoopGroup(com.couchbase.client.deps.io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(com.couchbase.client.deps.io.netty.channel.epoll.EpollEventLoopGroup) IoPoolShutdownHook(com.couchbase.client.core.env.resources.IoPoolShutdownHook) DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) EpollEventLoopGroup(com.couchbase.client.deps.io.netty.channel.epoll.EpollEventLoopGroup) DefaultLatencyMetricsCollectorConfig(com.couchbase.client.core.metrics.DefaultLatencyMetricsCollectorConfig) DefaultMetricsCollectorConfig(com.couchbase.client.core.metrics.DefaultMetricsCollectorConfig) MetricsCollectorConfig(com.couchbase.client.core.metrics.MetricsCollectorConfig) LatencyMetricsCollectorConfig(com.couchbase.client.core.metrics.LatencyMetricsCollectorConfig) NioEventLoopGroup(com.couchbase.client.deps.io.netty.channel.nio.NioEventLoopGroup)

Aggregations

IoPoolShutdownHook (com.couchbase.client.core.env.resources.IoPoolShutdownHook)1 DefaultLatencyMetricsCollectorConfig (com.couchbase.client.core.metrics.DefaultLatencyMetricsCollectorConfig)1 DefaultMetricsCollectorConfig (com.couchbase.client.core.metrics.DefaultMetricsCollectorConfig)1 LatencyMetricsCollectorConfig (com.couchbase.client.core.metrics.LatencyMetricsCollectorConfig)1 MetricsCollectorConfig (com.couchbase.client.core.metrics.MetricsCollectorConfig)1 DefaultSelectStrategyFactory (com.couchbase.client.deps.io.netty.channel.DefaultSelectStrategyFactory)1 EventLoopGroup (com.couchbase.client.deps.io.netty.channel.EventLoopGroup)1 SelectStrategyFactory (com.couchbase.client.deps.io.netty.channel.SelectStrategyFactory)1 EpollEventLoopGroup (com.couchbase.client.deps.io.netty.channel.epoll.EpollEventLoopGroup)1 NioEventLoopGroup (com.couchbase.client.deps.io.netty.channel.nio.NioEventLoopGroup)1 DefaultThreadFactory (com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory)1 DefaultCouchbaseEnvironment (com.couchbase.client.java.env.DefaultCouchbaseEnvironment)1 TemporaryFailureException (com.couchbase.client.java.error.TemporaryFailureException)1 DBException (com.yahoo.ycsb.DBException)1 ThreadFactory (java.util.concurrent.ThreadFactory)1