Search in sources :

Example 1 with IpcSharedMemoryServerEndpoint

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

the class IgfsServer method createEndpoint.

/**
 * Create server IPC endpoint.
 *
 * @param endpointCfg Endpoint configuration.
 * @param mgmt Management flag.
 * @return Server endpoint.
 * @throws IgniteCheckedException If failed.
 */
private IpcServerEndpoint createEndpoint(IgfsIpcEndpointConfiguration endpointCfg, boolean mgmt) throws IgniteCheckedException {
    A.notNull(endpointCfg, "endpointCfg");
    IgfsIpcEndpointType typ = endpointCfg.getType();
    if (typ == null)
        throw new IgniteCheckedException("Failed to create server endpoint (type is not specified)");
    switch(typ) {
        case SHMEM:
            {
                IpcSharedMemoryServerEndpoint endpoint = new IpcSharedMemoryServerEndpoint(igfsCtx.kernalContext().config().getWorkDirectory());
                endpoint.setPort(endpointCfg.getPort());
                endpoint.setSize(endpointCfg.getMemorySize());
                endpoint.setTokenDirectoryPath(endpointCfg.getTokenDirectoryPath());
                return endpoint;
            }
        case TCP:
            {
                IpcServerTcpEndpoint endpoint = new IpcServerTcpEndpoint();
                endpoint.setHost(endpointCfg.getHost());
                endpoint.setPort(endpointCfg.getPort());
                endpoint.setManagement(mgmt);
                return endpoint;
            }
        default:
            throw new IgniteCheckedException("Failed to create server endpoint (type is unknown): " + typ);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgfsIpcEndpointType(org.apache.ignite.igfs.IgfsIpcEndpointType) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint)

Example 2 with IpcSharedMemoryServerEndpoint

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

the class TcpCommunicationSpi method resetShmemServer.

/**
 * Creates new shared memory communication server.
 *
 * @return Server.
 * @throws IgniteCheckedException If failed.
 */
@Nullable
private IpcSharedMemoryServerEndpoint resetShmemServer() throws IgniteCheckedException {
    if (boundTcpShmemPort >= 0)
        throw new IgniteCheckedException("Shared memory server was already created on port " + boundTcpShmemPort);
    if (shmemPort == -1 || U.isWindows())
        return null;
    IgniteCheckedException lastEx = null;
    // If configured TCP port is busy, find first available in range.
    for (int port = shmemPort; port < shmemPort + locPortRange; port++) {
        try {
            IgniteConfiguration cfg = ignite.configuration();
            IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(log, cfg.getNodeId(), igniteInstanceName, cfg.getWorkDirectory());
            srv.setPort(port);
            srv.omitOutOfResourcesWarning(true);
            srv.start();
            boundTcpShmemPort = port;
            // Ack Port the TCP server was bound to.
            if (log.isInfoEnabled())
                log.info("Successfully bound shared memory communication to TCP port [port=" + boundTcpShmemPort + ", locHost=" + locHost + ']');
            return srv;
        } catch (IgniteCheckedException e) {
            lastEx = e;
            if (log.isDebugEnabled())
                log.debug("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + locHost + ']');
        }
    }
    // If free port wasn't found.
    throw new IgniteCheckedException("Failed to bind shared memory communication to any port within range [startPort=" + locPort + ", portRange=" + locPortRange + ", locHost=" + locHost + ']', lastEx);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with IpcSharedMemoryServerEndpoint

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

the class IgfsServer method start.

/**
 * Starts this server.
 *
 * @throws IgniteCheckedException If failed.
 */
public void start() throws IgniteCheckedException {
    srvEndpoint = createEndpoint(endpointCfg, mgmt);
    if (U.isWindows() && srvEndpoint instanceof IpcSharedMemoryServerEndpoint)
        throw new IgniteCheckedException(IpcSharedMemoryServerEndpoint.class.getSimpleName() + " should not be configured on Windows (configure " + IpcServerTcpEndpoint.class.getSimpleName() + ")");
    if (srvEndpoint instanceof IpcServerTcpEndpoint) {
        IpcServerTcpEndpoint srvEndpoint0 = (IpcServerTcpEndpoint) srvEndpoint;
        srvEndpoint0.setManagement(mgmt);
        if (srvEndpoint0.getHost() == null) {
            if (mgmt) {
                String locHostName = igfsCtx.kernalContext().config().getLocalHost();
                try {
                    srvEndpoint0.setHost(U.resolveLocalHost(locHostName).getHostAddress());
                } catch (IOException e) {
                    throw new IgniteCheckedException("Failed to resolve local host: " + locHostName, e);
                }
            } else
                // Bind non-management endpoint to 127.0.0.1 by default.
                srvEndpoint0.setHost("127.0.0.1");
        }
    }
    igfsCtx.kernalContext().resource().injectGeneric(srvEndpoint);
    srvEndpoint.start();
    // IpcServerEndpoint.getPort contract states return -1 if there is no port to be registered.
    if (srvEndpoint.getPort() >= 0)
        igfsCtx.kernalContext().ports().registerPort(srvEndpoint.getPort(), TCP, srvEndpoint.getClass());
    hnd = new IgfsIpcHandler(igfsCtx, endpointCfg, mgmt);
    // Start client accept worker.
    acceptWorker = new AcceptWorker();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IOException(java.io.IOException) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint)

Example 4 with IpcSharedMemoryServerEndpoint

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

the class HadoopExternalCommunication method resetShmemServer.

/**
 * Creates new shared memory communication server.
 * @return Server.
 * @throws IgniteCheckedException If failed.
 */
@Nullable
private IpcSharedMemoryServerEndpoint resetShmemServer() throws IgniteCheckedException {
    if (boundTcpShmemPort >= 0)
        throw new IgniteCheckedException("Shared memory server was already created on port " + boundTcpShmemPort);
    if (shmemPort == -1 || U.isWindows())
        return null;
    IgniteCheckedException lastEx = null;
    // If configured TCP port is busy, find first available in range.
    for (int port = shmemPort; port < shmemPort + locPortRange; port++) {
        try {
            IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(log.getLogger(IpcSharedMemoryServerEndpoint.class), locProcDesc.processId(), igniteInstanceName, workDir);
            srv.setPort(port);
            srv.omitOutOfResourcesWarning(true);
            srv.start();
            boundTcpShmemPort = port;
            // Ack Port the TCP server was bound to.
            if (log.isInfoEnabled())
                log.info("Successfully bound shared memory communication to TCP port [port=" + boundTcpShmemPort + ", locHost=" + locHost + ']');
            return srv;
        } catch (IgniteCheckedException e) {
            lastEx = e;
            if (log.isDebugEnabled())
                log.debug("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + locHost + ']');
        }
    }
    // If free port wasn't found.
    throw new IgniteCheckedException("Failed to bind shared memory communication to any port within range [startPort=" + locPort + ", portRange=" + locPortRange + ", locHost=" + locHost + ']', lastEx);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryClientEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with IpcSharedMemoryServerEndpoint

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

the class IpcSharedMemoryBenchmarkReader 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;
        }
    });
    try (IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory())) {
        new IgniteTestResources().inject(srv);
        srv.start();
        for (int i = 0; i < nThreads; i++) {
            final IpcEndpoint endPnt = srv.accept();
            new Thread(new Runnable() {

                @Override
                public void run() {
                    InputStream space = null;
                    try {
                        space = endPnt.inputStream();
                        byte[] buf = new byte[DST_BUFFER_SIZE];
                        int pos = 0;
                        while (!done) {
                            int maxRead = Math.min(buf.length - pos, DFLT_BUF_SIZE);
                            int read = space.read(buf, pos, maxRead);
                            if (read == -1) {
                                X.println("Space has been closed");
                                return;
                            }
                            transferCntr.addAndGet(read);
                            pos += read;
                            if (pos >= buf.length)
                                pos = 0;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        U.closeQuiet(space);
                    }
                }
            }).start();
        }
    }
    JOptionPane.showMessageDialog(null, "Press OK to stop READER.");
    done = true;
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) InputStream(java.io.InputStream) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IpcSharedMemoryServerEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)5 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)3 IpcServerTcpEndpoint (org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint)2 Nullable (org.jetbrains.annotations.Nullable)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgfsIpcEndpointType (org.apache.ignite.igfs.IgfsIpcEndpointType)1 IpcSharedMemoryClientEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint)1 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)1