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;
}
Aggregations