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));
}
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));
}
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);
}
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());
}
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());
}
Aggregations