0
Java 프로젝트의 경우 응용 프로그램을로드 할 때 데이터베이스에서 데이터를 캐싱하기 위해 hazelcast 서버와 클라이언트 모델을 사용하고 있습니다. 이 내 hazelcast.xml 아래메모리 데이터 그리드의 Hazelcast는 spring jpa와 비교할 때 매우 느림
<hazelcast>
<group>
<name>dev</name>
<password>dev-pass</password>
</group>
<management-center enabled="true">http://localhost:8080/mancenter</management-center>
<network>
<port auto-increment="true">5701</port>
<join>
<multicast enabled="false"></multicast>
<tcp-ip enabled="true">
<member>172.22.3.74</member>
<!--<interface>127.0.0.1</interface>-->
</tcp-ip> </join>
<interfaces enabled="false">
<interface>10.10.1.*</interface>
</interfaces>
<symmetric-encryption enabled="false">
<algorithm>PBEWithMD5AndDES</algorithm>
<!-- salt value to use when generating the secret key -->
<salt>thesalt</salt>
<!-- pass phrase to use when generating the secret key -->
<password>thepass</password>
<!-- iteration count to use when generating the secret key -->
<iteration-count>19</iteration-count>
</symmetric-encryption>
</network>
<properties>
<property name="hazelcast.http.healthcheck.enabled">true</property>
<property name="hazelcast.health.monitoring.delay.seconds">5</property>
<property name="hazelcast.health.monitoring.level">NOISY</property>
</properties>
<map name="scripMasterMap">
<near-cache name="default">
<in-memory-format>BINARY</in-memory-format>
<time-to-live-seconds>300</time-to-live-seconds>
<max-idle-seconds>100</max-idle-seconds>
</near-cache>
<backup-count>1</backup-count>
<time-to-live-seconds>8000</time-to-live-seconds>
<max-idle-seconds>3000</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<eviction-percentage>25</eviction-percentage>
<merge-policy>hz.ADD_NEW_ENTRY</merge-policy>
</map>
hazelcast 서버 코드입니다.
RefData.java :
ClientConfig cl = new ClientConfig();
HazelcastInstance client = Hazelcast.newHazelcastClient(cl);
IMap<Object, Object> map = cl.getMap("scripMasterMap");
return map;
아래는 hazelcast 클라이언트 맵에서 데이터를 반환하는 내 방법 :
HazelcastInstance in = Hazelcast.newHazelcastInstance();
IMap<Integer, ScripMaster> map = in.getMap("scripMasterMap");
for(ScripMaster scripMaster: scripMasterService.getAllScripMasterList()) {
scripMasterMap.put(scripMaster.getAllToken(), scripMaster);
}
아래 hazelcast 클라이언트 코드입니다.
public Set<String> getAssetByInstrumentName(
IMap<Integer, ScripMaster> map, String instrument) {
Set<String> myset = new HashSet<String>();
Predicate namePredicate = Predicates.equal("instrument", instrument);
Collection<ScripMaster> assets = map.values(namePredicate);
for(Iterator<ScripMaster> it = assets.iterator(); it.hasNext();) {
ScripMaster scripmaster = it.next();
myset.put(scripmaster.getAsset());
}
return myset;
}
이것은 직설적 인 코드입니다. 클라이언트가 메모리에서 데이터를 가질 수 있도록 수행해야 할 사항이 있습니까? 이 부분은 지금 해결되었습니다.
public Set<String> getAllCommodity(IMap<Integer, ScripMaster> map) {
Set<String> commoditySet = new HashSet<String>();
Aggregator<Map.Entry<Integer, ScripMaster>, Set<String>> aggregation = new CommodityAggregator();
PropertyExtractor<ScripMaster, String> propertyExtractor = new CommodityPropertyExtractor();
commoditySet = map.aggregate(aggregation);
// Aggregators.distinct("scripMaster.commodity");
// Aggregators.distinct();
LOG.info("Number of commodities loaded::" + commoditySet.size());
return commoditySet;
}
public class CommodityAggregator extends Aggregator <Map.Entry<Integer, ScripMaster>, Set<String>> {
Set<String> commoditySet = new HashSet<String>();
@Override
public void accumulate(Map.Entry<Integer, ScripMaster> input) {
commoditySet.add(input.getValue().getCommodity());
}
@Override
public void combine(Aggregator aggregator) {
}
@Override
public Set<String> aggregate() {
return commoditySet;
}
}
hazelcast.xml 콘텐츠를 추가 할 수 있습니까? – noctarius
@noctarius hazelcast.xml을 추가했습니다. –
감사합니다. 어떤 종류의 직렬화를 사용합니까? 객체 트리가 얼마나 복잡합니까? Hazelcast와 같은 시스템에서는 항상 직렬화 및 비 직렬화를 수행해야하므로 훌륭하고 빠른 직렬화가 중요합니다. – noctarius