Search in sources :

Example 1 with IgniteThreadPoolExecutor

use of org.apache.ignite.thread.IgniteThreadPoolExecutor in project ignite by apache.

the class GridTestMain method localPoolRun.

/**
     *
     */
private static void localPoolRun() {
    X.println("Local thread pool run...");
    ExecutorService exe = new IgniteThreadPoolExecutor(400, 400, 0, new ArrayBlockingQueue<Runnable>(400) {

        @Override
        public boolean offer(Runnable runnable) {
            try {
                put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return true;
        }
    });
    long start = System.currentTimeMillis();
    final IgniteCache<GridTestKey, Long> cache = G.ignite().cache("partitioned");
    // Collocate computations and data.
    for (long i = 0; i < GridTestConstants.ENTRY_COUNT; i++) {
        final long key = i;
        exe.submit(new Runnable() {

            @Override
            public void run() {
                Long val = cache.localPeek(new GridTestKey(key), CachePeekMode.ONHEAP);
                if (val == null || val != key)
                    throw new RuntimeException("Invalid value found [key=" + key + ", val=" + val + ']');
            }
        });
        if (i % 10000 == 0)
            X.println("Executed jobs: " + i);
    }
    long end = System.currentTimeMillis();
    X.println("Executed " + GridTestConstants.ENTRY_COUNT + " computations in " + (end - start) + "ms.");
}
Also used : IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) ExecutorService(java.util.concurrent.ExecutorService) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor)

Example 2 with IgniteThreadPoolExecutor

use of org.apache.ignite.thread.IgniteThreadPoolExecutor in project ignite by apache.

the class SqlListenerProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    IgniteConfiguration cfg = ctx.config();
    OdbcConfiguration odbcCfg = cfg.getOdbcConfiguration();
    if (odbcCfg != null) {
        try {
            HostAndPortRange hostPort;
            if (F.isEmpty(odbcCfg.getEndpointAddress())) {
                hostPort = new HostAndPortRange(OdbcConfiguration.DFLT_TCP_HOST, OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO);
            } else {
                hostPort = HostAndPortRange.parse(odbcCfg.getEndpointAddress(), OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO, "Failed to parse ODBC endpoint address");
            }
            assertParameter(odbcCfg.getThreadPoolSize() > 0, "threadPoolSize > 0");
            odbcExecSvc = new IgniteThreadPoolExecutor("odbc", cfg.getIgniteInstanceName(), odbcCfg.getThreadPoolSize(), odbcCfg.getThreadPoolSize(), 0, new LinkedBlockingQueue<Runnable>());
            InetAddress host;
            try {
                host = InetAddress.getByName(hostPort.host());
            } catch (Exception e) {
                throw new IgniteCheckedException("Failed to resolve ODBC host: " + hostPort.host(), e);
            }
            Exception lastErr = null;
            for (int port = hostPort.portFrom(); port <= hostPort.portTo(); port++) {
                try {
                    GridNioFilter[] filters = new GridNioFilter[] { new GridNioAsyncNotifyFilter(ctx.igniteInstanceName(), odbcExecSvc, log) {

                        @Override
                        public void onSessionOpened(GridNioSession ses) throws IgniteCheckedException {
                            proceedSessionOpened(ses);
                        }
                    }, new GridNioCodecFilter(new SqlListenerBufferedParser(), log, false) };
                    GridNioServer<byte[]> srv0 = GridNioServer.<byte[]>builder().address(host).port(port).listener(new SqlListenerNioListener(ctx, busyLock, odbcCfg.getMaxOpenCursors())).logger(log).selectorCount(DFLT_SELECTOR_CNT).igniteInstanceName(ctx.igniteInstanceName()).serverName("odbc").tcpNoDelay(DFLT_TCP_NODELAY).directBuffer(DFLT_TCP_DIRECT_BUF).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(odbcCfg.getSocketSendBufferSize()).socketReceiveBufferSize(odbcCfg.getSocketReceiveBufferSize()).filters(filters).directMode(false).idleTimeout(Long.MAX_VALUE).build();
                    srv0.start();
                    srv = srv0;
                    ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
                    log.info("ODBC processor has started on TCP port " + port);
                    lastErr = null;
                    break;
                } catch (Exception e) {
                    lastErr = e;
                }
            }
            assert (srv != null && lastErr == null) || (srv == null && lastErr != null);
            if (lastErr != null)
                throw new IgniteCheckedException("Failed to bind to any [host:port] from the range [" + "address=" + hostPort + ", lastErr=" + lastErr + ']');
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start ODBC processor.", e);
        }
    }
}
Also used : GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) HostAndPortRange(org.apache.ignite.internal.util.HostAndPortRange) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNioAsyncNotifyFilter(org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridNioCodecFilter(org.apache.ignite.internal.util.nio.GridNioCodecFilter) OdbcConfiguration(org.apache.ignite.configuration.OdbcConfiguration) InetAddress(java.net.InetAddress)

Example 3 with IgniteThreadPoolExecutor

use of org.apache.ignite.thread.IgniteThreadPoolExecutor in project ignite by apache.

the class ServerImpl method spiStart.

/** {@inheritDoc} */
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
    synchronized (mux) {
        spiState = DISCONNECTED;
    }
    utilityPool = new IgniteThreadPoolExecutor("disco-pool", spi.ignite().name(), 0, 1, 2000, new LinkedBlockingQueue<Runnable>());
    if (debugMode) {
        if (!log.isInfoEnabled())
            throw new IgniteSpiException("Info log level should be enabled for TCP discovery to work " + "in debug mode.");
        debugLogQ = new ConcurrentLinkedDeque<>();
        U.quietAndWarn(log, "TCP discovery SPI is configured in debug mode.");
    }
    // Clear addresses collections.
    fromAddrs.clear();
    noResAddrs.clear();
    msgWorker = new RingMessageWorker();
    msgWorker.start();
    if (tcpSrvr == null)
        tcpSrvr = new TcpServer();
    spi.initLocalNode(tcpSrvr.port, true);
    locNode = spi.locNode;
    // Start TCP server thread after local node is initialized.
    tcpSrvr.start();
    ring.localNode(locNode);
    if (spi.ipFinder.isShared())
        registerLocalNodeAddress();
    else {
        if (F.isEmpty(spi.ipFinder.getRegisteredAddresses()))
            throw new IgniteSpiException("Non-shared IP finder must have IP addresses specified in " + "TcpDiscoveryIpFinder.getRegisteredAddresses() configuration property " + "(specify list of IP addresses in configuration).");
        ipFinderHasLocAddr = spi.ipFinderHasLocalAddress();
    }
    if (spi.getStatisticsPrintFrequency() > 0 && log.isInfoEnabled()) {
        statsPrinter = new StatisticsPrinter();
        statsPrinter.start();
    }
    spi.stats.onJoinStarted();
    joinTopology();
    spi.stats.onJoinFinished();
    if (spi.ipFinder.isShared()) {
        ipFinderCleaner = new IpFinderCleaner();
        ipFinderCleaner.start();
    }
    spi.printStartInfo();
}
Also used : IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

IgniteThreadPoolExecutor (org.apache.ignite.thread.IgniteThreadPoolExecutor)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 InetAddress (java.net.InetAddress)1 ExecutorService (java.util.concurrent.ExecutorService)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 OdbcConfiguration (org.apache.ignite.configuration.OdbcConfiguration)1 HostAndPortRange (org.apache.ignite.internal.util.HostAndPortRange)1 GridNioAsyncNotifyFilter (org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter)1 GridNioCodecFilter (org.apache.ignite.internal.util.nio.GridNioCodecFilter)1 GridNioFilter (org.apache.ignite.internal.util.nio.GridNioFilter)1 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)1 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1