需要帮助来改善Hazelcast查询性能

时间:2018-12-31 14:11:50

标签: hazelcast hazelcast-imap

我大约要存储20万条记录。我已经实现了Java客户端,以从hazelcast Map中搜索记录。我没有在预期的时间内得到搜索结果。

一旦我对“ Hazelcast”进行“赞”或“查询”,就需要花费至少400到500毫秒。

可以更改服务器和客户端的配置以提高吞吐量吗?

我已将Java Bean信息与键值一起存储在Map中。我还在一个字段上创建了索引。还实现了身份序列化机制。

服务器端配置(使用XML文件设置服务器):

<map name="app-data">
    <in-memory-format>BINARY</in-memory-format>
    <statistics-enabled>false</statistics-enabled>
    <optimize-queries>false</optimize-queries>
    <cache-deserialized-values>INDEX-ONLY</cache-deserialized-values>
    <backup-count>0</backup-count>
    <async-backup-count>0</async-backup-count>
    <time-to-live-seconds>0</time-to-live-seconds>
    <max-idle-seconds>0</max-idle-seconds>
    <eviction-policy>NONE</eviction-policy>
    <max-size policy="PER_NODE">2147483647</max-size>
    <eviction-percentage>25</eviction-percentage>
    <min-eviction-check-millis>100</min-eviction-check-millis>
    <merge-policy batch-size="100">com.hazelcast.map.merge.LatestUpdateMapMergePolicy</merge-policy>
    <read-backup-data>false</read-backup-data>
    <hot-restart enabled="false">
        <fsync>false</fsync>
    </hot-restart>
    <map-store enabled="false" initial-mode="LAZY">
        <write-delay-seconds>0</write-delay-seconds>
        <write-batch-size>1</write-batch-size>
    </map-store>
    <indexes>
        <index ordered="true">index</index>
    </indexes>
</map>

<data-serializable-factories>
        <data-serializable-factory factory-id="1">com.tmobile.services.cacheserver.config.hazelcast.cache.serialization.CacheServerDataSerializableFactory</data-serializable-factory>

客户代码:

ClientConfig config = new ClientConfig();

    config.getSerializationConfig()
          .addDataSerializableFactory(
            CacheServerDataSerializableFactory.FACTORY_ID,
            new CacheServerDataSerializableFactory());

    config.getNetworkConfig().setAddresses(addresses).setConnectionAttemptPeriod(3000)
          .getSocketOptions().setBufferSize(256 * SocketOptions.KILO_BYTE);

    HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);
    return hazelcastInstance;

我使用的是hazelcast版本3.11。

下面是我用来存储信息的对象。

    public class AppData implements IdentifiedDataSerializable {

    private static final long serialVersionUID = 1L;

    @JsonIgnore
    private Long index = 0l;

    private Integer appId = 0;

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Integer getIndex() {
        return this.index;
    }

    public void setAppId(Integer appId) {
        this.appId = appId;
    }

    public Integer getAppId() {
        return this.appId;
    }

    @Override
    public final int hashCode() {
        return Objects.hash(this.getAppId());
    }

    @Override
    public void writeData(ObjectDataOutput out) throws IOException {
        out.writeLong(index);
        out.writeInt(appId);
    }

    @Override
    public void readData(ObjectDataInput in) throws IOException {

        this.index = in.readLong();
        this.appId = in.readInt();
    }

    @Override
    @JsonIgnore
    public int getFactoryId() {
        return CacheServerDataSerializableFactory.APP_DATE_FACTORY_TYPE;
    }

    @Override
    @JsonIgnore
    public int getId() {
        return CacheServerDataSerializableFactory.APP_DATE_ID;
    }
}

我在下面的查询/谓词中使用过过滤数据。

Predicate pred = new InPredicate(attribute, (Comparable[]) ((List) filterValue).toArray(new String[0]));
Collection<Object> items =  map.values(predicate);

1 个答案:

答案 0 :(得分:0)

@Prashant,由于IN谓词仅命中索引n次并直接获得结果,因此唯一可以改善的地方就是索引复制行为:https://docs.hazelcast.org/docs/3.11.1/manual/html-single/index.html#copying-indexes

您可以在成员config上设置以下属性并查看结果:

<property name="hazelcast.index.copy.behavior">NEVER</property>

请阅读有关索引复制行为的文档。