Search in sources :

Example 16 with TableManagerStats

use of herddb.core.stats.TableManagerStats in project herddb by diennea.

the class MultiDMLOnSameRecordTest method testWithFullTableScan.

@Test
public void testWithFullTableScan() throws Exception {
    Path baseDir = folder.newFolder().toPath();
    ServerConfiguration serverConfiguration = newServerConfigurationWithAutoPort(baseDir);
    serverConfiguration.set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 10 * 1024);
    serverConfiguration.set(ServerConfiguration.PROPERTY_MAX_DATA_MEMORY, 1024 * 1024 / 4);
    serverConfiguration.set(ServerConfiguration.PROPERTY_MAX_PK_MEMORY, 1024 * 1024);
    serverConfiguration.set(ServerConfiguration.PROPERTY_CHECKPOINT_PERIOD, 0);
    serverConfiguration.set(ServerConfiguration.PROPERTY_DATADIR, folder.newFolder().getAbsolutePath());
    serverConfiguration.set(ServerConfiguration.PROPERTY_LOGDIR, folder.newFolder().getAbsolutePath());
    try (Server server = new Server(serverConfiguration)) {
        server.start();
        server.waitForStandaloneBoot();
        DBManager manager = server.getManager();
        execute(manager, "CREATE TABLE mytable (id string primary key, n1 long, k2 string)", Collections.emptyList());
        ExecutorService threadPool = Executors.newFixedThreadPool(THREADPOLSIZE);
        try {
            List<Future> futures = new ArrayList<>();
            AtomicLong updates = new AtomicLong();
            AtomicLong deletes = new AtomicLong();
            AtomicLong inserts = new AtomicLong();
            AtomicLong duplicatePkErrors = new AtomicLong();
            for (int i = 0; i < TESTSIZE; i++) {
                futures.add(threadPool.submit(new Runnable() {

                    @Override
                    public void run() {
                        Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

                            @Override
                            public void uncaughtException(Thread t, Throwable e) {
                                e.printStackTrace();
                            }
                        });
                        try {
                            int k = ThreadLocalRandom.current().nextInt(10);
                            long value = ThreadLocalRandom.current().nextInt(100) + 1000;
                            String key = "test_" + k;
                            boolean update = ThreadLocalRandom.current().nextBoolean();
                            boolean insert = ThreadLocalRandom.current().nextBoolean();
                            boolean delete = ThreadLocalRandom.current().nextBoolean();
                            if (update) {
                                updates.incrementAndGet();
                                System.out.println("do " + Thread.currentThread() + " update on " + Bytes.from_string(key));
                                execute(manager, "UPDATE mytable set n1=? WHERE k2=?", Arrays.asList(value, key));
                            } else if (insert) {
                                System.out.println("do " + Thread.currentThread() + " insert on " + Bytes.from_string(key));
                                inserts.incrementAndGet();
                                try {
                                    execute(manager, "INSERT INTO mytable(n1, id, k2) values(?,?,?)", Arrays.asList(value, key, key));
                                } catch (DuplicatePrimaryKeyException ok) {
                                    duplicatePkErrors.incrementAndGet();
                                }
                            } else if (delete) {
                                System.out.println("do " + Thread.currentThread() + " delete on " + Bytes.from_string(key));
                                deletes.incrementAndGet();
                                execute(manager, "DELETE FROM mytable WHERE k2=?", Arrays.asList(key));
                            }
                        } catch (Throwable err) {
                            err.printStackTrace();
                            throw new RuntimeException(err);
                        }
                    }
                }));
            }
            for (Future f : futures) {
                f.get();
            }
            System.out.println("stats::updates:" + updates);
            System.out.println("stats::deletes:" + deletes);
            System.out.println("stats::inserts:" + inserts);
            System.out.println("stats::duplicatePkErrors:" + duplicatePkErrors);
            TableManagerStats stats = server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getTableManager("mytable").getStats();
            System.out.println("stats::tablesize:" + stats.getTablesize());
            System.out.println("stats::dirty records:" + stats.getDirtyrecords());
            System.out.println("stats::unload count:" + stats.getUnloadedPagesCount());
            System.out.println("stats::load count:" + stats.getLoadedPagesCount());
            System.out.println("stats::buffers used mem:" + stats.getBuffersUsedMemory());
        } finally {
            threadPool.shutdown();
            threadPool.awaitTermination(1, TimeUnit.MINUTES);
        }
    }
    // restart and recovery
    try (Server server = new Server(serverConfiguration)) {
        server.start();
        server.waitForTableSpaceBoot(TableSpace.DEFAULT, 300000, true);
    }
}
Also used : Path(java.nio.file.Path) Server(herddb.server.Server) ServerConfiguration(herddb.server.ServerConfiguration) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) DBManager(herddb.core.DBManager) TableManagerStats(herddb.core.stats.TableManagerStats) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) DuplicatePrimaryKeyException(herddb.model.DuplicatePrimaryKeyException) Test(org.junit.Test)

Aggregations

TableManagerStats (herddb.core.stats.TableManagerStats)16 ArrayList (java.util.ArrayList)11 Path (java.nio.file.Path)9 ExecutorService (java.util.concurrent.ExecutorService)9 Future (java.util.concurrent.Future)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 Test (org.junit.Test)8 ServerConfiguration (herddb.server.ServerConfiguration)6 Map (java.util.Map)6 DBManager (herddb.core.DBManager)5 DataScanner (herddb.model.DataScanner)5 Table (herddb.model.Table)5 Server (herddb.server.Server)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)4 ClientConfiguration (herddb.client.ClientConfiguration)3 DMLResult (herddb.client.DMLResult)3 GetResult (herddb.client.GetResult)3 HDBClient (herddb.client.HDBClient)3 HDBConnection (herddb.client.HDBConnection)3