[ 
https://issues.apache.org/jira/browse/HTTPCORE-145?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12567998#action_12567998
 ] 

peter curtis commented on HTTPCORE-145:
---------------------------------------

Thanks in advance, Oleg.

I am using this code for a propietary application. This application needs 
serializing a huge amount of objects, for this reason we opt to choose NIO as 
the best solution for these requirements. When we are checking this code with 
JProfiler and after a fewer minutes of good performance. Just in the moment 
that one of the IODispatcher threads appears in green (meaning running state) 
the rest of the IODispatchers fall into IO networks tasks. Since this moment 
the application stops receiving requests. I haven't  any idea what is 
happening.  Apparently, all that it seems that NIO selectors do not run 
properly. 


private class ControllerServerChannel {
                class HttpHandler implements HttpRequestHandler {
                
                        public HttpHandler() {
                        }
                
                        public void handle(final HttpRequest request, final 
HttpResponse response, final HttpContext context) throws HttpException, 
IOException {
                
                                ByteArrayOutputStream baos = new 
ByteArrayOutputStream();
                                HeaderIterator it = request.headerIterator();
                                byte[] entityContent;
                                URI uri = null;
                
                                
baos.write(request.getRequestLine().toString().getBytes());
                                baos.write(RPC.EOL);
                                while (it.hasNext()) {
                                        
baos.write(it.nextHeader().toString().getBytes());
                                        baos.write(RPC.EOL);
                                }
                
                                baos.write(RPC.EOL);
                                if (request instanceof 
HttpEntityEnclosingRequest) {
                                        HttpEntity entity = 
((HttpEntityEnclosingRequest) request).getEntity();
                                        entity.consumeContent();
                                        entityContent = 
EntityUtils.toByteArray(entity);
                                        baos.write(entityContent);
                                }
                
                                try {
                                        uri = new 
URI(URLDecoder.decode(request.getRequestLine().getUri(), "UTF-8"));
                                } catch (URISyntaxException e) {
                                }
                
                                InputStream in = new 
ByteArrayInputStream(baos.toByteArray());
                                OutputStream out = new ByteArrayOutputStream();
                                final InputOutput io = new InputOutput(uri, in, 
out);
                                baos.close();
                
                                EntityTemplate body = new EntityTemplate(new 
ContentProducer() {
                
                                        public void writeTo(final OutputStream 
outstream) throws IOException {
                                                
outstream.write(((ByteArrayOutputStream) io.getOutputStream()).toByteArray());
                                        }
                                });
                                workerGroup.process(io, io);
                                response.setEntity(body);
                        }
                
                }

                private ListeningIOReactor ioReactor;
                private HttpParams params;
                private BufferingHttpServiceHandler handler;
                private InetSocketAddress inetSocketAddress;
                private SSLContext sslContext;

                ControllerServerChannel(ChannelServiceConfig serviceCfg) throws 
Exception {
                        SocketEndPointConfig socketEndPointConfig = 
(SocketEndPointConfig) serviceCfg.getEndPointConfig();
                        params = new BasicHttpParams();
                        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 
5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 
1024).setBooleanParameter(
                                        
CoreConnectionPNames.STALE_CONNECTION_CHECK, 
false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, 
false).setParameter(CoreProtocolPNames.ORIGIN_SERVER,
                                        "HttpComponents/1.1");
                        inetSocketAddress = 
getInetSocketAddress(socketEndPointConfig);
                        sslContext = 
getSSLContext(socketEndPointConfig.getSSLParams());
                        BasicHttpProcessor httpproc = new BasicHttpProcessor();
                        httpproc.addInterceptor(new ResponseDate());
                        httpproc.addInterceptor(new ResponseServer());
                        httpproc.addInterceptor(new ResponseContent());
                        httpproc.addInterceptor(new ResponseConnControl());

                        handler = new BufferingHttpServiceHandler(httpproc, new 
DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params);

                        // Set up request handlers
                        HttpRequestHandlerRegistry reqistry = new 
HttpRequestHandlerRegistry();
                        reqistry.register("*", new HttpHandler());

                        handler.setHandlerResolver(reqistry);
                }

                private void start() throws IOException {

                        Thread t = new Thread(new Runnable() {
                                public void run() {
                                        try {
                                                IOEventDispatch ioEventDispatch;
                                                if (isSecure()) {
                                                        ioEventDispatch = new 
SSLServerIOEventDispatch(handler, sslContext, params);
                                                } else
                                                        ioEventDispatch = new 
DefaultServerIOEventDispatch(handler, params);

                                                ListeningIOReactor ioReactor = 
new DefaultListeningIOReactor(1, params);
                                                
ioReactor.listen(inetSocketAddress);
                                                
ioReactor.execute(ioEventDispatch);
                                        } catch (IOException ioe) {
                                                Logger.log(this, 
"startService()", "Error starting socket", ioe, Logger.Severity.WARNING);
                                        }
                                }
                        }, "LogServer:ChannelService");
                        t.setPriority(Thread.MAX_PRIORITY);
                        t.start();
                }

                private void stop() throws IOException {
                        ioReactor.shutdown();
                }

                private boolean isSecure() {
                        return sslContext != null;
                }

                private int getPort() {
                        return inetSocketAddress.getPort();
                }

                private InetSocketAddress 
getInetSocketAddress(SocketEndPointConfig config) throws 
ConfigInitializationException {

                        InetAddress bindAddress = null;
                        int port;
                        String bindIP = config.getBindIP();
                        if (bindIP != null && bindIP.length() > 0) {
                                try {
                                        bindAddress = 
InetAddress.getByName(bindIP);
                                } catch (UnknownHostException uhe) {
                                        String msg = "Specified address not 
valid for: " + bindIP;
                                        Logger.log(this, 
"init(SocketEndPointConfig)", msg, Logger.Severity.SEVERE_ERROR);
                                        throw new 
ConfigInitializationException(msg, uhe);
                                }
                        }
                        port = config.getPort();

                        if (port < 0) {
                                String msg = "Server port cannot be negative [" 
+ port + "]";
                                Logger.log(this, "init(SocketEndPointConfig)", 
msg, Logger.Severity.SEVERE_ERROR);
                                throw new ConfigInitializationException(msg);
                        } else if (port > 65535) {
                                String msg = "Server port cannot be bigger than 
65535 [" + port + "]";
                                Logger.log(this, "init(SocketEndPointConfig)", 
msg, Logger.Severity.SEVERE_ERROR);
                                throw new ConfigInitializationException(msg);
                        }
                        return new InetSocketAddress(bindAddress, port);
                }

                private SSLContext getSSLContext(SSLParamsConfig spc) throws 
IOException {
                        SSLContext ctx = null;
                        if (spc == null)
                                return ctx;
                        String keystore = spc.getKeyStore().getAbsolutePath();
                        char[] passphrase = 
EncryptedPassword.decryptProperty(spc.getKeyStorePassword()).toCharArray();

                        try {
                                java.security.Security.addProvider(new 
com.sun.net.ssl.internal.ssl.Provider());
                                ctx = SSLContext.getInstance("TLS");
                                KeyManagerFactory kmf = 
KeyManagerFactory.getInstance("SunX509");
                                KeyStore ks = KeyStore.getInstance("JKS");
                                ks.load(new FileInputStream(keystore), 
passphrase);
                                kmf.init(ks, passphrase);
                                ctx.init(kmf.getKeyManagers(), null, null);
                        } catch (java.security.GeneralSecurityException gse) {
                                throw new IOException(gse.getMessage());
                        }
                        return ctx;
                }

        }


> After fewer minutes IODispatchers workers stop attenting requests
> -----------------------------------------------------------------
>
>                 Key: HTTPCORE-145
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-145
>             Project: HttpComponents Core
>          Issue Type: Bug
>          Components: HttpCore NIO
>    Affects Versions: 4.0-beta2
>         Environment: Linux Debian and Windows
>            Reporter: peter curtis
>            Priority: Critical
>
> I have a NIO HTTP server dispatching a massive loading, after fewer minutes 
> IODispathers workers (10 workers) unexpecteadly stop attending requests.
> I am using JProfiler and I have checked that after a while of  good 
> performance, one of threads fall into running and the rest in IO netwoks 
> tasks. After that the application silently stops attending.
> Thank you in advance.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to