Search in sources :

Example 1 with CacheStatic

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);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) LayerCachePool(io.mycat.cache.LayerCachePool) CachePool(io.mycat.cache.CachePool) CacheStatic(io.mycat.cache.CacheStatic) LayerCachePool(io.mycat.cache.LayerCachePool) FieldPacket(io.mycat.net.mysql.FieldPacket) Map(java.util.Map) CacheService(io.mycat.cache.CacheService)

Example 2 with CacheStatic

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"));
}
Also used : CacheStatic(io.mycat.cache.CacheStatic) Test(org.junit.Test)

Example 3 with CacheStatic

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));
}
Also used : CacheStatic(io.mycat.cache.CacheStatic) Test(org.junit.Test)

Example 4 with CacheStatic

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());
}
Also used : CacheStatic(io.mycat.cache.CacheStatic)

Aggregations

CacheStatic (io.mycat.cache.CacheStatic)4 Test (org.junit.Test)2 CachePool (io.mycat.cache.CachePool)1 CacheService (io.mycat.cache.CacheService)1 LayerCachePool (io.mycat.cache.LayerCachePool)1 EOFPacket (io.mycat.net.mysql.EOFPacket)1 FieldPacket (io.mycat.net.mysql.FieldPacket)1 RowDataPacket (io.mycat.net.mysql.RowDataPacket)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1