0

so I'm trying to see what's the fastest way to write to Chronicle Queue in a multithread env so I have the following:

 public static void main(String[] args) throws  Exception{
    final String path = args[0];
    int times = Integer.parseInt(args[1]);
    int num = Integer.parseInt(args[2]);

    AtomicInteger nextid = new AtomicInteger(0);
    ThreadLocal<Integer> id = ThreadLocal.withInitial(() -> nextid.getAndIncrement());

    ChronicleTest test = new ChronicleTest();
    ChronicleWriter writer = test.new ChronicleWriter(path);

    CountDownLatch start = new CountDownLatch(1);
    CountDownLatch done = new CountDownLatch(num);
    Thread[] threads = new Thread[num];
    long[] samples = new long[times * num];
    for (int i = 0; i < num; i ++) {
        threads[i] = new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    start.await();
                    for (int i = 0; i < times; i++) {
                        int j = i + times*id.get().intValue();
                        long s = System.nanoTime();
                        writer.write(j + " DGirr5JgGVmxhvmaoO0c5MVVOUIEJxWa6nVStPnqmRl3T4hKE9tiwNjn6322uhgr2Fs4hDG8aKYvIB4O0733fx18EqGqNsshaSKoouky5ZekGK3vO87nfSUOz6uDD0olOp35QJQKPgr7tNlFgQP7BImcCyMPFCCm3yhSvOUgiVAD9W9BC3cqlKjQebOG4EkqzRIzwZjxbnIeK2YttfrvOvUJs0e9WBhXUVibi5Ks2j9ROQu2q0PJII4NYyN1a5YW2UKxyng3bRrtBVFqMSamtFzJ23EE4Y7rbQyeCVJhIKRM1LRvcGLUYZqKICWwDtOjGcbXUIlLLYiJcnVRZ4gNRvbFXvTL4XDjhD3uP5S8DjnkeAIBZcQ4VEUf30x65pTGLhWjOMV6jtiEQOWKB3nsuPMhcS1lP3wTQztViW7T8IsQlA5kvVAsnT5A7pojS1CffcYz4a2Rwqf9w6mhTPPZXgpDGArtThW3a69rwjsQxEY9aTwi0Pu0jlSAMmvOA158QFsSeJvLoJXILfocgjNEkj7iVcO0Rc6eC6b5EhJU3wv80EEHnORMXpQVuAuPyao7vJsx06TMcXf9t7Py4qxplVPhptIzrKs2qke2t5A8O4LQzq19OfEQsQGEjqHSbnfWXjfuntuFR8rV4VMyLZO1z3K7HmHtCEy14p5u0C0lj7vmtCnrOum0bnG2MwaAR7DJPIpOtwRObli5K5grv54AWnJyagpRX5e3eTEA8NAKO8oDZuLaoCvgavv9ciFrJcIDmyleVweiVrHs1fQXJoELzFpH4BmvzBuUjfZ8ORSIZsVuq4Hpls19GIA8opb1mSBt7MTifLPauo8WDWRoNi9DvjL4Z08Je6DvrhAFXasU2CMugg5EZ06OXexU17qnvxx2Vz9s9E5U50jDemySZ78KcZ6nqhQKIXUrkTktoEan2JXxI2NNSqEYifwly8ZO2MDquPe4J11rAcOqYp9y6Kb4NtFpNysM1evrLPvCx8oe");

                        long e = System.nanoTime();
                        samples[j] = e - s;
                    }
                    done.countDown();
                } catch (Exception e){
                    e.printStackTrace();
                }
            }
        });
    }
    for (int i = 0; i < num; i ++) {
        try {
            threads[i].start();
        } catch (Exception e){

        }
    }
    long startT = System.currentTimeMillis();
    start.countDown();
    done.await();
    long endT = System.currentTimeMillis();
    System.out.println("Time to complete [" + times + "] iteration in [" + (endT - startT) + " ms] and threads [" + num + "]");

    System.out.println("#######");
    for (int i = 0; i < times * num; i ++){
        System.out.println(samples[i]);
    }
}

private class ChronicleWriter {

    SingleChronicleQueue m_cqueue;
    ThreadLocal<ExcerptAppender> m_appender;
    ChronicleWriter(String path ) {
        m_cqueue = SingleChronicleQueueBuilder.binary(path).build();
        m_appender = new ThreadLocal<ExcerptAppender>() {
            protected ExcerptAppender initialValue() {
                return m_cqueue.acquireAppender();
            }
        };
    }

    void write(String msg){
        m_appender.get().writeText(msg);
    }
}

And I ran with parameters: path 2500 40

For some reason, this keeps crashing with core dump. What am I doing wrong? My disk has lots of disk space so that shouldn't matter. Thanks!!

Theboy
  • 353
  • 1
  • 2
  • 8

1 Answers1

0

If your program is crashing due to OutOfMemory error then note that the disk space and the actual space used by the program may differ. You may need to increase jvm heap size.

Refer below link to increase jvm heap size What are the Xms and Xmx parameters when starting JVMs?

Or

Refer below link if you are running your program through eclipse http://www.planetofbits.com/eclipse/increase-jvm-heap-size-in-eclipse/

I have tried your program with following version of chronicle-queue and it works fine.

<dependency>
    <groupId>net.openhft</groupId>
    <artifactId>chronicle-queue</artifactId>
    <version>4.5.14</version>
</dependency>
pranay jain
  • 352
  • 1
  • 2
  • 15