Search in sources :

Example 6 with MycatPropertyConf

use of io.mycat.memory.unsafe.utils.MycatPropertyConf in project Mycat-Server by MyCATApache.

the class TaskMemoryManagerSuite method encodePageNumberAndOffsetOffHeap.

@Test
public void encodePageNumberAndOffsetOffHeap() {
    final MycatPropertyConf conf = new MycatPropertyConf().set("mycat.memory.offHeap.enabled", "true").set("mycat.memory.offHeap.size", "1000");
    final DataNodeMemoryManager manager = new DataNodeMemoryManager(new TestMemoryManager(conf), 0);
    final MemoryBlock dataPage = manager.allocatePage(256, null);
    // In off-heap mode, an offset is an absolute address that may require more than 51 bits to
    // encode. This map exercises that corner-case:
    final long offset = ((1L << DataNodeMemoryManager.OFFSET_BITS) + 10);
    final long encodedAddress = manager.encodePageNumberAndOffset(dataPage, offset);
    Assert.assertEquals(null, manager.getPage(encodedAddress));
    Assert.assertEquals(offset, manager.getOffsetInPage(encodedAddress));
}
Also used : DataNodeMemoryManager(io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager) MycatPropertyConf(io.mycat.memory.unsafe.utils.MycatPropertyConf) Test(org.junit.Test)

Example 7 with MycatPropertyConf

use of io.mycat.memory.unsafe.utils.MycatPropertyConf in project Mycat-Server by MyCATApache.

the class TaskMemoryManagerSuite method encodePageNumberAndOffsetOnHeap.

@Test
public void encodePageNumberAndOffsetOnHeap() {
    final DataNodeMemoryManager manager = new DataNodeMemoryManager(new TestMemoryManager(new MycatPropertyConf().set("mycat.memory.offHeap.enabled", "false")), 0);
    final MemoryBlock dataPage = manager.allocatePage(256, null);
    final long encodedAddress = manager.encodePageNumberAndOffset(dataPage, 64);
    Assert.assertEquals(dataPage.getBaseObject(), manager.getPage(encodedAddress));
    Assert.assertEquals(64, manager.getOffsetInPage(encodedAddress));
}
Also used : DataNodeMemoryManager(io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager) MycatPropertyConf(io.mycat.memory.unsafe.utils.MycatPropertyConf) Test(org.junit.Test)

Example 8 with MycatPropertyConf

use of io.mycat.memory.unsafe.utils.MycatPropertyConf in project Mycat-Server by MyCATApache.

the class TestSorter method main.

public static void main(String[] args) throws Exception {
    MyCatMemory myCatMemory;
    MemoryManager memoryManager;
    MycatPropertyConf conf;
    myCatMemory = new MyCatMemory();
    memoryManager = myCatMemory.getResultMergeMemoryManager();
    conf = myCatMemory.getConf();
    for (int i = 0; i < TASK_SIZE; i++) {
        Thread thread = new Thread(new TestSorter(myCatMemory, memoryManager, conf));
        thread.start();
    }
    while (countDownLatch.getCount() != 0) {
        System.err.println("count ========================>" + countDownLatch.getCount());
        Thread.sleep(1000);
    }
    System.err.println(TASK_SIZE + " tasks sorter finished ok !!!!!!!!!");
    System.exit(1);
}
Also used : MycatPropertyConf(io.mycat.memory.unsafe.utils.MycatPropertyConf) DataNodeMemoryManager(io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager) MemoryManager(io.mycat.memory.unsafe.memory.mm.MemoryManager) MyCatMemory(io.mycat.memory.MyCatMemory)

Example 9 with MycatPropertyConf

use of io.mycat.memory.unsafe.utils.MycatPropertyConf in project Mycat-Server by MyCATApache.

the class TaskMemoryManagerSuite method leakedPageMemoryIsDetected.

@Test
public void leakedPageMemoryIsDetected() {
    final DataNodeMemoryManager manager = new DataNodeMemoryManager(new ResultMergeMemoryManager(new MycatPropertyConf().set("mycat.memory.offHeap.enabled", "false").set("mycat.memory.offHeap.size", "32768"), 1, Long.MAX_VALUE), 0);
    // leak memory
    manager.allocatePage(4096, null);
    Assert.assertEquals(4096, manager.getMemoryConsumptionForThisConnection());
    Assert.assertEquals(4096, manager.cleanUpAllAllocatedMemory());
}
Also used : DataNodeMemoryManager(io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager) ResultMergeMemoryManager(io.mycat.memory.unsafe.memory.mm.ResultMergeMemoryManager) MycatPropertyConf(io.mycat.memory.unsafe.utils.MycatPropertyConf) Test(org.junit.Test)

Example 10 with MycatPropertyConf

use of io.mycat.memory.unsafe.utils.MycatPropertyConf in project Mycat-Server by MyCATApache.

the class TaskMemoryManagerSuite method cooperativeSpilling.

@Test
public void cooperativeSpilling() throws InterruptedException {
    final TestMemoryManager memoryManager = new TestMemoryManager(new MycatPropertyConf());
    memoryManager.limit(100);
    final DataNodeMemoryManager manager = new DataNodeMemoryManager(memoryManager, 0);
    TestMemoryConsumer c1 = new TestMemoryConsumer(manager);
    TestMemoryConsumer c2 = new TestMemoryConsumer(manager);
    c1.use(100);
    Assert.assertEquals(100, c1.getUsed());
    c2.use(100);
    Assert.assertEquals(100, c2.getUsed());
    // spilled
    Assert.assertEquals(0, c1.getUsed());
    c1.use(100);
    Assert.assertEquals(100, c1.getUsed());
    // spilled
    Assert.assertEquals(0, c2.getUsed());
    c1.use(50);
    // spilled
    Assert.assertEquals(50, c1.getUsed());
    Assert.assertEquals(0, c2.getUsed());
    c2.use(50);
    Assert.assertEquals(50, c1.getUsed());
    Assert.assertEquals(50, c2.getUsed());
    c1.use(100);
    Assert.assertEquals(100, c1.getUsed());
    // spilled
    Assert.assertEquals(0, c2.getUsed());
    c1.free(20);
    Assert.assertEquals(80, c1.getUsed());
    c2.use(10);
    Assert.assertEquals(80, c1.getUsed());
    Assert.assertEquals(10, c2.getUsed());
    c2.use(100);
    Assert.assertEquals(100, c2.getUsed());
    // spilled
    Assert.assertEquals(0, c1.getUsed());
    c1.free(0);
    c2.free(100);
    Assert.assertEquals(0, manager.cleanUpAllAllocatedMemory());
}
Also used : DataNodeMemoryManager(io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager) MycatPropertyConf(io.mycat.memory.unsafe.utils.MycatPropertyConf) Test(org.junit.Test)

Aggregations

MycatPropertyConf (io.mycat.memory.unsafe.utils.MycatPropertyConf)11 Test (org.junit.Test)10 DataNodeMemoryManager (io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager)9 MyCatMemory (io.mycat.memory.MyCatMemory)2 TestMemoryConsumer (io.mycat.memory.unsafe.memory.TestMemoryConsumer)2 TestMemoryManager (io.mycat.memory.unsafe.memory.TestMemoryManager)2 MemoryManager (io.mycat.memory.unsafe.memory.mm.MemoryManager)2 MemoryBlock (io.mycat.memory.unsafe.memory.MemoryBlock)1 ResultMergeMemoryManager (io.mycat.memory.unsafe.memory.mm.ResultMergeMemoryManager)1 BufferHolder (io.mycat.memory.unsafe.row.BufferHolder)1 StructType (io.mycat.memory.unsafe.row.StructType)1 UnsafeRow (io.mycat.memory.unsafe.row.UnsafeRow)1 UnsafeRowWriter (io.mycat.memory.unsafe.row.UnsafeRowWriter)1 DataNodeDiskManager (io.mycat.memory.unsafe.storage.DataNodeDiskManager)1 SerializerManager (io.mycat.memory.unsafe.storage.SerializerManager)1 PrefixComparator (io.mycat.memory.unsafe.utils.sort.PrefixComparator)1 RowPrefixComputer (io.mycat.memory.unsafe.utils.sort.RowPrefixComputer)1 UnsafeExternalRowSorter (io.mycat.memory.unsafe.utils.sort.UnsafeExternalRowSorter)1 ColMeta (io.mycat.sqlengine.mpp.ColMeta)1 OrderCol (io.mycat.sqlengine.mpp.OrderCol)1