Search in sources :

Example 6 with IpcEndpoint

use of org.apache.ignite.internal.util.ipc.IpcEndpoint in project ignite by apache.

the class IpcSharedMemoryBenchmarkWriter method main.

/**
     * @param args Args.
     * @throws IgniteCheckedException If failed.
     */
public static void main(String[] args) throws IgniteCheckedException {
    IpcSharedMemoryNativeLoader.load(null);
    int nThreads = args.length > 0 ? Integer.parseInt(args[0]) : 1;
    final AtomicLong transferCntr = new AtomicLong();
    Thread collector = new Thread(new Runnable() {

        @SuppressWarnings("BusyWait")
        @Override
        public void run() {
            try {
                while (!done) {
                    Thread.sleep(5000);
                    X.println("Transfer rate: " + transferCntr.getAndSet(0) / (1024 * 1024 * 5) + " MB/sec");
                }
            } catch (InterruptedException ignored) {
            // No-op.
            }
        }
    });
    collector.start();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            System.out.println("Shutting down...");
            done = true;
        }
    });
    for (int i = 0; i < nThreads; i++) {
        final int threadNum = i;
        new Thread(new Runnable() {

            @Override
            public void run() {
                IpcEndpoint client = null;
                try {
                    client = IpcEndpointFactory.connectEndpoint("shmem:" + IpcSharedMemoryServerEndpoint.DFLT_IPC_PORT, new JavaLogger());
                    OutputStream space = client.outputStream();
                    byte[] buf = new byte[SRC_BUFFER_SIZE];
                    int pos = 0;
                    while (!done) {
                        int snd = Math.min(DFLT_BUF_SIZE, buf.length - pos);
                        space.write(buf, pos, snd);
                        // Measure only 1 client.
                        if (threadNum == 0)
                            transferCntr.addAndGet(snd);
                        pos += snd;
                        if (pos >= buf.length)
                            pos = 0;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (client != null)
                        client.close();
                }
            }
        }).start();
    }
    JOptionPane.showMessageDialog(null, "Press OK to stop WRITER.");
    done = true;
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) AtomicLong(java.util.concurrent.atomic.AtomicLong) OutputStream(java.io.OutputStream) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) JavaLogger(org.apache.ignite.logger.java.JavaLogger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)6 IpcSharedMemoryServerEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)3 InputStream (java.io.InputStream)2 LinkedList (java.util.LinkedList)2 Callable (java.util.concurrent.Callable)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)2 OutputStream (java.io.OutputStream)1 IpcServerEndpoint (org.apache.ignite.internal.util.ipc.IpcServerEndpoint)1 IpcSharedMemoryClientEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint)1 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)1 JavaLogger (org.apache.ignite.logger.java.JavaLogger)1 IgniteThread (org.apache.ignite.thread.IgniteThread)1 Nullable (org.jetbrains.annotations.Nullable)1