Search in sources :

Example 1 with InfluxServer

use of io.apisense.embed.influx.InfluxServer in project invesdwin-context-persistence by subes.

the class InfluxDBPerformanceTest method testInfluxDbPerformanceAsync.

@Test
public void testInfluxDbPerformanceAsync() throws Exception {
    final int freeHttpPort = Network.getFreeServerPort();
    final int freeUdpPort = Network.getFreeServerPort();
    final InfluxServer server = startInfluxDB(freeHttpPort, freeUdpPort);
    server.start();
    try {
        Thread.sleep(10 * 1000);
        final String dbname = "influxDbPerformance";
        final String policyname = "defaultPolicy";
        final String measurementName = "measurementsPerformance";
        final InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:" + freeHttpPort);
        influxDB.createDatabase(dbname);
        influxDB.createRetentionPolicy(policyname, dbname, "9999d", 1, true);
        BatchPoints batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
        final Instant writesStart = new Instant();
        int i = 0;
        for (final FDate date : newValues()) {
            final Point point = Point.measurement(measurementName).time(date.millisValue(), TimeUnit.MILLISECONDS).tag("hashKey", HASH_KEY).addField("value", date.millisValue()).build();
            batch.point(point);
            i++;
            if (i % FLUSH_INTERVAL == 0) {
                printProgress("Writes", writesStart, i, VALUES);
                influxDB.write(batch);
                batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
            }
        }
        influxDB.write(batch);
        batch = null;
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
        TimeUnit.SECONDS.sleep(1);
        final Instant readsStart = new Instant();
        for (int reads = 1; reads <= READS; reads++) {
            final IMutableReference<FDate> prevValueRef = new VolatileReference<>();
            final AtomicBoolean finished = new AtomicBoolean();
            final int readsFinal = reads;
            final AtomicInteger count = new AtomicInteger();
            influxDB.query(new Query("Select value from " + measurementName + " where hashKey = '" + HASH_KEY + "'", dbname), 10_000, new Consumer<QueryResult>() {

                @Override
                public void accept(final QueryResult queryResult) {
                    try {
                        final List<Result> range = queryResult.getResults();
                        if (range == null || range.isEmpty()) {
                            return;
                        }
                        final Result firstResult = range.get(0);
                        if (firstResult == null) {
                            return;
                        }
                        final List<Series> series = firstResult.getSeries();
                        if (series == null || series.isEmpty()) {
                            return;
                        }
                        final List<List<Object>> firstSeries = series.get(0).getValues();
                        if (firstSeries == null) {
                            return;
                        }
                        for (int result = 0; result < firstSeries.size(); result++) {
                            final Double valueDouble = (Double) firstSeries.get(result).get(1);
                            final FDate value = new FDate(valueDouble.longValue());
                            final FDate prevValue = prevValueRef.get();
                            if (prevValue != null) {
                                Assertions.checkTrue(prevValue.isBefore(value));
                            }
                            prevValueRef.set(value);
                            count.incrementAndGet();
                        }
                    } catch (final Throwable t) {
                        Err.process(t);
                    }
                }
            }, () -> finished.set(true));
            while (!finished.get() && count.get() != VALUES) {
                TimeUnit.NANOSECONDS.sleep(1);
            }
            Assertions.checkEquals(count.get(), VALUES);
            printProgress("Reads", readsStart, VALUES * readsFinal, VALUES * READS);
        }
        printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
    } finally {
        server.stop();
    }
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) Query(org.influxdb.dto.Query) Instant(de.invesdwin.util.time.Instant) VolatileReference(de.invesdwin.util.concurrent.reference.VolatileReference) ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Point(org.influxdb.dto.Point) Point(org.influxdb.dto.Point) FDate(de.invesdwin.util.time.date.FDate) QueryResult(org.influxdb.dto.QueryResult) Result(org.influxdb.dto.QueryResult.Result) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryResult(org.influxdb.dto.QueryResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InfluxDB(org.influxdb.InfluxDB) InfluxServer(io.apisense.embed.influx.InfluxServer) List(java.util.List) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 2 with InfluxServer

use of io.apisense.embed.influx.InfluxServer in project invesdwin-context-persistence by subes.

the class InfluxDBPerformanceTest method startInfluxDB.

private InfluxServer startInfluxDB(final int freeHttpPort, final int freeUdpPort) throws IOException {
    final InfluxServer.Builder builder = new InfluxServer.Builder();
    // configuration to start InfluxDB server with HTTP on port `freeHttpPort`
    // and default backup restore port
    final InfluxConfigurationWriter influxConfig = // by default auth is disabled
    new InfluxConfigurationWriter.Builder().setHttp(freeHttpPort).setUdp(// If you happen to need udp enabled, by default to 'udp' database
    freeUdpPort).build();
    // let's start both of protocols, HTTP and UDP
    builder.setInfluxConfiguration(influxConfig);
    final InfluxServer server = builder.build();
    return server;
}
Also used : InfluxConfigurationWriter(io.apisense.embed.influx.configuration.InfluxConfigurationWriter) InfluxServer(io.apisense.embed.influx.InfluxServer)

Example 3 with InfluxServer

use of io.apisense.embed.influx.InfluxServer in project invesdwin-context-persistence by subes.

the class InfluxDBPerformanceTest method testInfluxDbPerformanceSync.

@Test
public void testInfluxDbPerformanceSync() throws Exception {
    final int freeHttpPort = Network.getFreeServerPort();
    final int freeUdpPort = Network.getFreeServerPort();
    final InfluxServer server = startInfluxDB(freeHttpPort, freeUdpPort);
    server.start();
    try {
        Thread.sleep(10 * 1000);
        final String dbname = "influxDbPerformance";
        final String policyname = "defaultPolicy";
        final String measurementName = "measurementsPerformance";
        final InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:" + freeHttpPort);
        influxDB.createDatabase(dbname);
        influxDB.createRetentionPolicy(policyname, dbname, "9999d", 1, true);
        BatchPoints batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
        final Instant writesStart = new Instant();
        int i = 0;
        for (final FDate date : newValues()) {
            final Point point = Point.measurement(measurementName).time(date.millisValue(), TimeUnit.MILLISECONDS).tag("hashKey", HASH_KEY).addField("value", date.millisValue()).build();
            batch.point(point);
            i++;
            if (i % FLUSH_INTERVAL == 0) {
                printProgress("Writes", writesStart, i, VALUES);
                influxDB.write(batch);
                batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
            }
        }
        influxDB.write(batch);
        batch = null;
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
        readIterator(dbname, measurementName, influxDB);
    } finally {
        server.stop();
    }
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) InfluxDB(org.influxdb.InfluxDB) Instant(de.invesdwin.util.time.Instant) InfluxServer(io.apisense.embed.influx.InfluxServer) ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Point(org.influxdb.dto.Point) Point(org.influxdb.dto.Point) FDate(de.invesdwin.util.time.date.FDate) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Aggregations

InfluxServer (io.apisense.embed.influx.InfluxServer)3 ATest (de.invesdwin.context.test.ATest)2 ProcessedEventsRateString (de.invesdwin.util.lang.ProcessedEventsRateString)2 Instant (de.invesdwin.util.time.Instant)2 FDate (de.invesdwin.util.time.date.FDate)2 InfluxDB (org.influxdb.InfluxDB)2 BatchPoints (org.influxdb.dto.BatchPoints)2 Point (org.influxdb.dto.Point)2 Test (org.junit.jupiter.api.Test)2 VolatileReference (de.invesdwin.util.concurrent.reference.VolatileReference)1 InfluxConfigurationWriter (io.apisense.embed.influx.configuration.InfluxConfigurationWriter)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Query (org.influxdb.dto.Query)1 QueryResult (org.influxdb.dto.QueryResult)1 Result (org.influxdb.dto.QueryResult.Result)1