<commit_before>/*
 * Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.spi.properties;

import com.hazelcast.config.AdvancedNetworkConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.EndpointConfig;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.SSLConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IndeterminateOperationStateException;
import com.hazelcast.instance.BuildInfo;
import com.hazelcast.instance.BuildInfoProvider;
import com.hazelcast.instance.EndpointQualifier;
import com.hazelcast.internal.cluster.fd.ClusterFailureDetectorType;
import com.hazelcast.internal.diagnostics.HealthMonitorLevel;
import com.hazelcast.internal.util.RuntimeAvailableProcessors;
import com.hazelcast.map.IMap;
import com.hazelcast.map.QueryResultSizeExceededException;
import com.hazelcast.map.impl.query.QueryResultSizeLimiter;
import com.hazelcast.query.Predicates;
import com.hazelcast.query.impl.IndexCopyBehavior;
import com.hazelcast.query.impl.predicates.QueryOptimizerFactory;
import com.hazelcast.spi.impl.operationservice.InvocationBuilder;
import com.hazelcast.spi.impl.operationservice.OperationService;

import java.util.Map;
import java.util.function.Function;

import static com.hazelcast.internal.util.Preconditions.checkPositive;
import static java.lang.Math.max;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

/**
 * Defines the name and default value for Hazelcast properties.
 */
@SuppressWarnings({"checkstyle:javadocvariable", "checkstyle:magicnumber"})
public final class GroupProperty {

    /**
     * Total number of partitions in the Hazelcast cluster.
     */
    public static final HazelcastProperty PARTITION_COUNT
            = new HazelcastProperty("hazelcast.partition.count", 271);

    /**
     * For more detail see {@link #PARTITION_OPERATION_THREAD_COUNT}.
     *
     * If this property is set to false, Hazelcast will default to 3.x style
     * operation thread configuration whereby the sum of the number of partition
     * threads and IO threads exceeds the number of cores.
     *
     * If this property is set to true (default) Hazelcast will subtract the
     * number of IO threads from the number of available processors and that will
     * be the number of partition threads.
     *
     * If explicit number of partition threads is configured, this property is
     * irrelevant.
     *
     * This property favors the typical get/set type of application. Application
     * that are number crunching or query heavy, will get a performance hit
     * because not all cores will be busy with processing operations since there
     * are less operation threads than processors. So for such applications it
     * is best to explicitly disable this property.
     */
    public static final HazelcastProperty PARTITION_OPERATION_THREAD_ISOLATED
            = new HazelcastProperty("hazelcast.operation.thread.isolated", new Function<HazelcastProperties, Boolean>() {
        @Override
        public Boolean apply(HazelcastProperties properties) {
            int availableProcessors = RuntimeAvailableProcessors.get();
            if (availableProcessors < 20) {
                return false;
            }

            int ioThreads = properties.getInteger(IO_INPUT_THREAD_COUNT) + properties.getInteger(IO_OUTPUT_THREAD_COUNT);
            if (ioThreads > 8) {
                return false;
            }

            return true;
        }
    });

    /**
     * The number of partition operation handler threads per member.
     * <p>
     * If this is less than the number of partitions on a member, partition operations
     * will queue behind other operations of different partitions.
     *
     * If the JVM detects 20 or more cores, and 'hazelcast.operation.thread.isolated' is set to true,
     * it will prevent creating more threads than available cores by
     * determining the number of operation threads as corecount-iothreadcount.
     * This will prevent that IO threads and partition threads will contend for cores and this leads to
     * increases throughput and less jitter.
     *
     * If explicit number of partition threads is configured, than the magic where we try to determine optimal
     * number of partition threads is bypassed.
     */
    public static final HazelcastProperty PARTITION_OPERATION_THREAD_COUNT
            = new HazelcastProperty("hazelcast.operation.thread.count", new Function<HazelcastProperties, Integer>() {
        @Override
        public Integer apply(HazelcastProperties properties) {
            int availableProcessors = RuntimeAvailableProcessors.get();
            boolean isolated = properties.getBoolean(PARTITION_OPERATION_THREAD_ISOLATED);

            if (isolated) {
                int ioThreads = properties.getInteger(IO_INPUT_THREAD_COUNT) + properties.getInteger(IO_OUTPUT_THREAD_COUNT);
                int partitionThreadCount = availableProcessors - ioThreads;
                return checkPositive(partitionThreadCount, "partitionThreadCount must be positive,"
                        + " but was " + partitionThreadCount);
            } else {
                return max(2, availableProcessors);
            }
        }
    });

    /**
     * The number of generic operation handler threads per member.
     * <p>
     * The default is max(2, processors/2);
     */
    public static final HazelcastProperty GENERIC_OPERATION_THREAD_COUNT
            = new HazelcastProperty("hazelcast.operation.generic.thread.count",
            (Function<HazelcastProperties, Integer>) o -> {<commit_msg>Removed the isolated operation thread flag<commit_after>/*
 * Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.spi.properties;

import com.hazelcast.config.AdvancedNetworkConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.EndpointConfig;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.SSLConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IndeterminateOperationStateException;
import com.hazelcast.instance.BuildInfo;
import com.hazelcast.instance.BuildInfoProvider;
import com.hazelcast.instance.EndpointQualifier;
import com.hazelcast.internal.cluster.fd.ClusterFailureDetectorType;
import com.hazelcast.internal.diagnostics.HealthMonitorLevel;
import com.hazelcast.internal.util.RuntimeAvailableProcessors;
import com.hazelcast.map.IMap;
import com.hazelcast.map.QueryResultSizeExceededException;
import com.hazelcast.map.impl.query.QueryResultSizeLimiter;
import com.hazelcast.query.Predicates;
import com.hazelcast.query.impl.IndexCopyBehavior;
import com.hazelcast.query.impl.predicates.QueryOptimizerFactory;
import com.hazelcast.spi.impl.operationservice.InvocationBuilder;
import com.hazelcast.spi.impl.operationservice.OperationService;

import java.util.Map;
import java.util.function.Function;

import static java.lang.Math.max;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

/**
 * Defines the name and default value for Hazelcast properties.
 */
@SuppressWarnings({"checkstyle:javadocvariable", "checkstyle:magicnumber"})
public final class GroupProperty {

    /**
     * Total number of partitions in the Hazelcast cluster.
     */
    public static final HazelcastProperty PARTITION_COUNT
            = new HazelcastProperty("hazelcast.partition.count", 271);

    /**
     * The number of partition operation handler threads per member.
     * <p>
     * If this is less than the number of partitions on a member, partition operations
     * will queue behind other operations of different partitions.
     *
     */
    public static final HazelcastProperty PARTITION_OPERATION_THREAD_COUNT
            = new HazelcastProperty("hazelcast.operation.thread.count",
            (Function<HazelcastProperties, Integer>) properties -> max(2, RuntimeAvailableProcessors.get()));

    /**
     * The number of generic operation handler threads per member.
     * <p>
     * The default is max(2, processors/2);
     */
    public static final HazelcastProperty GENERIC_OPERATION_THREAD_COUNT
            = new HazelcastProperty("hazelcast.operation.generic.thread.count",
            (Function<HazelcastProperties, Integer>) o -> {
{'fraction_non_alphanumeric': 0.07539640869473906, 'fraction_numerical': 0.0044103748818649586, 'mean_word_length': 3.714851485148515, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7488983', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2523, 'n_words': 773}