package net.openhft.chronicle.queue;

import net.openhft.chronicle.bytes.MappedBytes;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.OS;

import java.io.File;
import java.io.FileNotFoundException;

/*
-Dtarget=/home/peter/tmp/
-Dthroughput=500
-Dorg.slf4j.simpleLogger.defaultLogLevel=info
-Druns=80
 */

public class MultiQueueStressMain {
    static final int queueCount = Integer.getInteger("queues", 25);
    static final int throughput = Integer.getInteger("throughput", 50); // MB/s
    static final String target = System.getProperty("target", OS.TARGET);
    static final int runs = Integer.getInteger("runs", 10);

    public static void main(String[] args) throws FileNotFoundException {
        for (int t = 0; t < runs; t++) {
            System.out.print("Writing ... ");
            long start0 = System.currentTimeMillis();
            int count = 0;
            String baseDir = target + "/deleteme/" + System.nanoTime();
            new File(baseDir).mkdirs();
            MappedBytes[] queues = new MappedBytes[queueCount];
            int pagesPer10Second = (int) (10L * (throughput << 20) / queueCount / (4 << 10));
            for (int i = 0; i < queueCount; i++) {
                queues[i] = MappedBytes.mappedBytes(baseDir + "/" + count++, pagesPer10Second * (4 << 10));
            }
            long mid1 = System.currentTimeMillis();
            for (int i = 0; i < pagesPer10Second; i++) {
                for (MappedBytes bytes : queues) {
                    bytes.writeLong(i * (4 << 10), i);
                }
            }
            long mid2 = System.currentTimeMillis();
            for (MappedBytes bytes : queues) {
                bytes.release();
            }
            long end0 = System.currentTimeMillis();
            long time0 = end0 - start0;
            System.out.printf("Took %.3f seconds to write %,d MB, create: %.3f, write: %.3f, close: %.3f%n",
                    time0 / 1e3, throughput * 10, (mid1 - start0) / 1e3, (mid2 - mid1) / 1e3, (end0 - mid2) / 1e3);
            long delay = 10000 - time0;
            if (delay > 0)
                Jvm.pause(delay);
        }
    }
}

@@ -245,17 +245,17 @@
 ter/tmp/
-%0A
+ 
 -Dthroug
@@ -263,12 +263,13 @@
 put=
-500%0A
+1000 
 -Dor
@@ -313,17 +313,17 @@
 info
-%0A
+ 
 -Druns=
-8
+4
 0%0A *
@@ -763,54 +763,8 @@
 ) %7B%0A
-            System.out.print(%22Writing ... %22);%0A
     
@@ -1153,32 +1153,149 @@
 ueCount; i++) %7B%0A
+                long start1 = System.currentTimeMillis();%0A                String filename = baseDir + %22/%22 + count++;%0A
                 
@@ -1330,39 +1330,24 @@
 edBytes(
-baseDir + %22/%22 + count++
+filename
 , pagesP
@@ -1363,32 +1363,227 @@
 d * (4 %3C%3C 10));%0A
+                long time1 = System.currentTimeMillis() - start1;%0A                if (time1 %3E 20)%0A                    System.out.printf(%22Creating %25s took %25.3f seconds%25n%22, filename, time1 / 1e3);%0A
             %7D%0A  

Add a memory map stress tester.