use of io.mycat.cache.CacheStatic in project Mycat-Server by MyCATApache.
the class ShowCache method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
byte packetId = eof.packetId;
CacheService cacheService = MycatServer.getInstance().getCacheService();
for (Map.Entry<String, CachePool> entry : cacheService.getAllCachePools().entrySet()) {
String cacheName = entry.getKey();
CachePool cachePool = entry.getValue();
if (cachePool instanceof LayerCachePool) {
for (Map.Entry<String, CacheStatic> staticsEntry : ((LayerCachePool) cachePool).getAllCacheStatic().entrySet()) {
RowDataPacket row = getRow(cacheName + '.' + staticsEntry.getKey(), staticsEntry.getValue(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
} else {
RowDataPacket row = getRow(cacheName, cachePool.getCacheStatic(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.cache.CacheStatic in project Mycat-Server by MyCATApache.
the class EnCachePoolTest method testBasic.
@Test
public void testBasic() {
enCachePool.putIfAbsent("2", "dn2");
enCachePool.putIfAbsent("1", "dn1");
Assert.assertEquals("dn2", enCachePool.get("2"));
Assert.assertEquals("dn1", enCachePool.get("1"));
Assert.assertEquals(null, enCachePool.get("3"));
CacheStatic statics = enCachePool.getCacheStatic();
Assert.assertEquals(statics.getItemSize(), 2);
Assert.assertEquals(statics.getPutTimes(), 2);
Assert.assertEquals(statics.getAccessTimes(), 3);
Assert.assertEquals(statics.getHitTimes(), 2);
Assert.assertTrue(statics.getLastAccesTime() > 0);
Assert.assertTrue(statics.getLastPutTime() > 0);
Assert.assertTrue(statics.getLastAccesTime() > 0);
// wait expire
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
Assert.assertEquals(null, enCachePool.get("2"));
Assert.assertEquals(null, enCachePool.get("1"));
}
use of io.mycat.cache.CacheStatic in project Mycat-Server by MyCATApache.
the class DefaultLayedCachePoolTest method testBasic.
@Test
public void testBasic() {
layedCachePool.putIfAbsent("2", "dn2");
layedCachePool.putIfAbsent("1", "dn1");
layedCachePool.putIfAbsent("company", 1, "dn1");
layedCachePool.putIfAbsent("company", 2, "dn2");
layedCachePool.putIfAbsent("goods", "1", "dn1");
layedCachePool.putIfAbsent("goods", "2", "dn2");
Assert.assertEquals("dn2", layedCachePool.get("2"));
Assert.assertEquals("dn1", layedCachePool.get("1"));
Assert.assertEquals(null, layedCachePool.get("3"));
Assert.assertEquals("dn1", layedCachePool.get("company", 1));
Assert.assertEquals("dn2", layedCachePool.get("company", 2));
Assert.assertEquals(null, layedCachePool.get("company", 3));
Assert.assertEquals("dn1", layedCachePool.get("goods", "1"));
Assert.assertEquals("dn2", layedCachePool.get("goods", "2"));
Assert.assertEquals(null, layedCachePool.get("goods", 3));
CacheStatic statics = layedCachePool.getCacheStatic();
Assert.assertEquals(statics.getItemSize(), 6);
Assert.assertEquals(statics.getPutTimes(), 6);
Assert.assertEquals(statics.getAccessTimes(), 9);
Assert.assertEquals(statics.getHitTimes(), 6);
Assert.assertTrue(statics.getLastAccesTime() > 0);
Assert.assertTrue(statics.getLastPutTime() > 0);
Assert.assertTrue(statics.getLastAccesTime() > 0);
// wait expire
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
Assert.assertEquals(null, layedCachePool.get("2"));
Assert.assertEquals(null, layedCachePool.get("1"));
Assert.assertEquals(null, layedCachePool.get("goods", "2"));
Assert.assertEquals(null, layedCachePool.get("company", 2));
}
use of io.mycat.cache.CacheStatic in project Mycat-Server by MyCATApache.
the class TestCachePoolPerformance method testSelectSpeed.
private void testSelectSpeed() {
System.out.println("test select speed for " + this.pool + " count:" + this.maxCacheCount);
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxCacheCount; i++) {
pool.get(i + "");
}
double used = (System.currentTimeMillis() - startTime) / 1000.0;
CacheStatic statics = pool.getCacheStatic();
System.out.println("used time:" + used + " tps:" + maxCacheCount / used + " cache hit:" + 100 * statics.getHitTimes() / statics.getAccessTimes());
}
Aggregations