Hazelcast客户端 - 卡住线程

时间:2015-07-30 04:23:20

标签: multithreading hazelcast

我正在使用Hazelcast 3.5.1

遇到挂起线程问题

我的应用程序将运行,然后默默地停止工作。

看来我在HZ客户端中有多个线程被卡住了。

客户端跟踪

State:TIMED_WAITING
Priority:5
java.lang.Object.wait(Native Method)
com.hazelcast.client.spi.impl.ClientInvocationFuture.get(ClientInvocationFuture.java:104)
com.hazelcast.client.spi.impl.ClientInvocationFuture.get(ClientInvocationFuture.java:89)
com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:130)
com.hazelcast.client.proxy.ClientMapProxy.get(ClientMapProxy.java:197)

服务器错误

    [ERROR] [2015-07-29 18:20:12,812] [hz._hzInstance_1_dev.partition-operation.thread-0] [][c.h.m.i.o.GetOperation] [[198.47.158.82]:5900 [dev] [3.5.1] io.protostuff.UninitializedMessageException]
com.hazelcast.nio.serialization.HazelcastSerializationException: io.protostuff.UninitializedMessageException
at com.hazelcast.nio.serialization.SerializationServiceImpl.handleException(SerializationServiceImpl.java:380) ~[hazelcast-3.5.1.jar:3.5.1]
at com.hazelcast.nio.serialization.SerializationServiceImpl.toData(SerializationServiceImpl.java:235) ~[hazelcast-3.5.1.jar:3.5.1]
at com.hazelcast.map.impl.record.DataRecordFactory.newRecord(DataRecordFactory.java:47) ~[hazelcast-3.5.1.jar:3.5.1]

客户端配置

public ClientConfig config() {
    final ClientConfig config = new ClientConfig();
    config.setExecutorPoolSize(100);
    setupLoggingConfig(config);
    setupNetworkConfig(config);
    setupGroupConfig(config);
    setupSerializationConfig(config);
    setupAdvancedConfig(config);
    return config;
}

private void setupAdvancedConfig(final ClientConfig config) {
    config.setProperty(GroupProperties.PROP_OPERATION_CALL_TIMEOUT_MILLIS, String.valueOf(5000));
}

private void setupLoggingConfig(final ClientConfig config) {
    config.setProperty("hazelcast.logging.type", "slf4j");
}

private void setupNetworkConfig(final ClientConfig config) {
    final ClientNetworkConfig networkConfig = config.getNetworkConfig();

    networkConfig.setConnectionTimeout(1000);
    networkConfig.setConnectionAttemptPeriod(3000);
    networkConfig.setConnectionAttemptLimit(2);
    networkConfig.setRedoOperation(true);
    networkConfig.setSmartRouting(true);
    setupNetworkSocketConfig(networkConfig);
}

private void setupNetworkSocketConfig(final ClientNetworkConfig networkConfig) {
    final SocketOptions socketOptions = networkConfig.getSocketOptions();
    socketOptions.setKeepAlive(false);
    socketOptions.setBufferSize(32);
    socketOptions.setLingerSeconds(3);
    socketOptions.setReuseAddress(false);
    socketOptions.setTcpNoDelay(false);
}

服务器配置

private void init(final Config config) {
    setupExecutorConfig(config);
    setupLoggingConfig(config);
    setupMapConfigs(config);
    setupNetworkConfig(config);
    setupGroupConfig(config);
    setupAdvancedConfig(config);
    setupSerializationConfig(config);
}

private void setupAdvancedConfig(final Config config) {
    config.setProperty(GroupProperties.PROP_OPERATION_CALL_TIMEOUT_MILLIS, String.valueOf(5000));
}

private void setupExecutorConfig(final Config config) {
    final ExecutorConfig executorConfig = new ExecutorConfig();
    executorConfig.setPoolSize(300);
    config.addExecutorConfig(executorConfig);

}

private void setupLoggingConfig(final Config config) {
    config.setProperty("hazelcast.logging.type", "slf4j");
}

private void setupNetworkConfig(final Config config) {
    final NetworkConfig networkCfg = config.getNetworkConfig();
    networkCfg.setPort(5900);
    networkCfg.setPortAutoIncrement(false);

    final JoinConfig join = networkCfg.getJoin();
    join.getMulticastConfig().setEnabled(false);
    for (final String server : getServers()) {
        join.getTcpIpConfig().addMember(server);
    }
}

private String[] getServers() {
    return PROPS.getProperty("store.servers").split(",");
}

private void setupMapConfigs(final Config config) {
    setupMapConfigXXX(config);
}

private void setupMapConfigXXX(final Config config) {
    final MapConfig mapConfig = setupMapConfigByName(config, XXX.class.getName());
    setupMapStoreConfigDummy(mapConfig);
    setupEvictionPolicy(mapConfig);
}


private void setupMapStoreConfigDummy(final MapConfig mapConfig) {
    final MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setClassName(DummyStore.class.getName()).setEnabled(true);
    mapConfig.setMapStoreConfig(mapStoreConfig);
}

private void setupEvictionPolicy(final MapConfig mapConfig) {
    mapConfig.setEvictionPolicy(EvictionPolicy.LFU);
    mapConfig.setMaxSizeConfig(oneGBSize());
}

private MapConfig setupMapConfigByName(final Config config, final String mapName) {
    final MapConfig mapConfig = new MapConfig();
    mapConfig.setName(mapName);
    mapConfig.setBackupCount(1);

    final NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setMaxSize(1000).setMaxIdleSeconds(300).setTimeToLiveSeconds(300);
    mapConfig.setNearCacheConfig(nearCacheConfig);

    config.addMapConfig(mapConfig);

    return mapConfig;
}

private MaxSizeConfig oneGBSize() {
    final MaxSizeConfig config = new MaxSizeConfig();
    config.setMaxSizePolicy(MaxSizePolicy.USED_HEAP_SIZE);
    config.setSize(1024);
    return config;
}

我希望客户端超时,但似乎没有发生。

1 个答案:

答案 0 :(得分:0)

我相信您应该通过属性ClientProperties.PROP_INVOCATION_TIMEOUT_SECONDS

配置客户端超时

然而,它只是一个创可贴。您应该找出序列化失败的真正根本原因。