Last active
August 29, 2015 13:56
-
-
Save enesakar/9123542 to your computer and use it in GitHub Desktop.
stats example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws InterruptedException { | |
| Config cfg = new XmlConfigBuilder().build(); | |
| cfg.setProperty("hazelcast.local.localAddress", "127.0.0.1"); | |
| cfg.setProperty(GroupProperties.PROP_HEALTH_MONITORING_LEVEL, HealthMonitorLevel.NOISY.toString()); | |
| // memory stats will be logged in every 10 seconds | |
| cfg.setProperty(GroupProperties.PROP_HEALTH_MONITORING_DELAY_SECONDS, "10"); | |
| String cacheName = "cache"; | |
| MemorySize memorySize = new MemorySize(100, MemoryUnit.MEGABYTES); | |
| OffHeapMemoryConfig memoryConfig = new OffHeapMemoryConfig() | |
| .setSize(memorySize).setEnabled(true); | |
| cfg.setOffHeapMemoryConfig(memoryConfig); | |
| SerializationConfig serializationConfig = cfg.getSerializationConfig(); | |
| serializationConfig.setAllowUnsafe(true); | |
| Hazelcast.newHazelcastInstance(cfg); | |
| HazelcastInstance client = HazelcastClient.newHazelcastClient(new ClientConfig()); | |
| CacheManager cacheManager = new HazelcastCachingProvider(client).getCacheManager(); | |
| final ICache<String, String> cache = (ICache) cacheManager.getCache(cacheName); | |
| Random random = new Random(System.currentTimeMillis()); | |
| for (int i = 0; i < 1000; i++) { | |
| cache.put("key" + i, "value" + i); | |
| cache.get("key" + random.nextInt(100)); | |
| CacheStats stats = cache.getStats(); | |
| System.out.println("CACHE STATS:"); | |
| System.out.println("Size:"+ stats.getSize()+ " - Hits:"+stats.getHits() + " - Misses:" + stats.getMisses()); | |
| Thread.sleep(1000); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment