| Config config = new Config();
config.setClusterName("cluster");
//Network config.setNetworkConfig(new NetworkConfig() .setJoin(new JoinConfig() .setMulticastConfig( new MulticastConfig() .setEnabled(false)) .setEurekaConfig( new EurekaConfig() .setEnabled(true) .setProperty("self-registration", "true") .setProperty("namespace", "hazelcast")) ) );
//Serialize config.setSerializationConfig( new SerializationConfig() .addDataSerializableFactory(SerializableFactory.FACTORY_ID, new SerializableFactory()) );
//backpressure config.setProperty("hazelcast.backpressure.enabled", "true"); config.setProperty("hazelcast.backpressure.max.concurrent.invocations.per.partition", "100"); config.setProperty("hazelcast.backpressure.syncwindow", "500"); config.setProperty("hazelcast.backpressure.backoff.timeout.millis", "60000"); config.setProperty("hazelcast.operation.backup.timeout.millis", "60000"); config.setProperty("hazelcast.client.max.concurrent.invocations", "200");
//thread 3*3(accept request+read data from other+write data to other) config.setProperty("hazelcast.io.thread.count", "3"); config.setProperty("hazelcast.operation.thread.count", "100");
//slow invalidation config.setProperty("hazelcast.slow.operation.detector.enabled", "true"); config.setProperty("hazelcast.slow.operation.detector.stacktrace.logging.enabled", "true"); config.setProperty("hazelcast.slow.operation.detector.log.purge.interval.seconds", "600"); config.setProperty("hazelcast.slow.operation.detector.log.retention.seconds", "600"); config.setProperty("hazelcast.slow.operation.detector.threshold.millis", "300");
//near cache invalidation config.setProperty("hazelcast.map.invalidation.batch.enabled", "true"); config.setProperty("hazelcast.map.invalidation.batch.size", "100"); config.setProperty("hazelcast.map.invalidation.batchfrequency.seconds", "5");
//当前 write-coalescing is false即保留全部变更, set per-node maximum capacity config.setProperty("hazelcast.map.write.behind.queue.capacity", "5000");
//map config List<CacheConfig> list = new ArrayList<>(); list.add(new CacheConfig("cache", 900, 50000));
list.forEach(e -> { config.addMapConfig(new MapConfig() .setName(e.getName()) .setInMemoryFormat(InMemoryFormat.BINARY) .setMetadataPolicy(MetadataPolicy.OFF) //backup .setBackupCount(0) .setAsyncBackupCount(1) //timeout .setTimeToLiveSeconds(e.getTimeout()) .setMaxIdleSeconds(e.getTimeout() / 2) //evict .setEvictionConfig(new EvictionConfig() .setEvictionPolicy(EvictionPolicy.LFU) .setMaxSizePolicy(MaxSizePolicy.PER_NODE) .setSize(e.getSize())) //backup read .setReadBackupData(true) //partition .setPartitioningStrategyConfig(new PartitioningStrategyConfig() .setPartitioningStrategy(new StringPartitioningStrategy())) //near cache .setNearCacheConfig(new NearCacheConfig() .setName(e.getName() + "_nc") .setInMemoryFormat(InMemoryFormat.OBJECT) .setCacheLocalEntries(true) .setInvalidateOnChange(true) .setLocalUpdatePolicy(NearCacheConfig.LocalUpdatePolicy.INVALIDATE) .setMaxIdleSeconds(e.getTimeout() / 10) .setEvictionConfig(new EvictionConfig() .setEvictionPolicy(EvictionPolicy.LFU) .setMaxSizePolicy(MaxSizePolicy.ENTRY_COUNT) .setSize(e.getSize() / 100)) ) //map store .setMapStoreConfig(new MapStoreConfig() .setEnabled(true) //保留最新,而不是全部变更 .setWriteCoalescing(true) ) );
});
return Hazelcast.newHazelcastInstance(config);
|