I am working to request http within a concurrent, threaded environment.
However, my system breaks down completely at very low throughput.
In almost pseudo-code:
ClientBootstrap bootstrap = new clientbootstrap (new NioClientSocketChannelFactory ()) bootstrap.setPipelineFactory (new HTTP clientPipelineFattery ()); Channel Future Future = Bootstrap.connect (new inset socket address (host, port)); Channel channel = future Wait uncontrollably (). GetChannel (); HttpRequest Request = New DefaultHttpRequest (); Channel.write (request); For example, to create a request, I am creating a clientbootstrap, and from there (via some hoops) to write a channel HTTPRequest. All this works and is good
However, in a concurrent situation, should every request go through the same hoops? I think that at the moment I am breaking things for me. Should I reuse the connection or my client should be completely structured differently?
Apart from this: I am doing this in closure, if it does make any difference at all.
No, you are doing the right thing, however, you should see your channel example Should be kept in context. Once you have that channel, as long as it is open, you do not need to create any other bootstrap. (If you are doing this.) It is that I have recently used in a project:
Class Client Connection (Constructor) // Configure Cluster Bootstrap = New Client Bootstrap (New NioClientSocketChannelFactory (Examiner.NewCached Threadpool), Exporter.NewCachad Threadpool ()); // Setup Pipeline Factory Bootstrap.setPipelineFactory (New ChannelPipelineFactory () {Public ChannelPipeline getPipeline () throws an exception {return channels, pipeline (// put your handlers here);}}); Class Client Connection Connection. (String host, int port) if (connected) () the new IllegalStateException "is already connected"); // Start connection connection Channel Future Future = Bootstrap.connect (new inset socket address (host, port)); Channel = future Wait uncontrollably (). GetChannel (); // The connection attempt fails or the connection fails until the connection closes. Channel.getCloseFuture () AddListener (New ChannelFutureListener) {@Override Pursue Public Null Operation Full (ChannelFoot for future Future) Exception {New Thread (New Runnabal) {Public Zero Run () // // Exit Thread Pool to exit The thread can not be executed in pool! Bootstrap.releaseExternalResources (); LOG.log (Level.INFO, "shut down");}}). Start ();}}); So, basically, I only refer to bootstrap and channel , though many of these lines out of the earlier code Not used much. Note: You should only execute bootstrap.release ExternalResources (); Once, when the application stops. In my case, the client sends some files, then closes the channel and once you give a connected channel example, you can use only one Required unless you turn it off. Once closed, you can remember bootstrap to create a new channel again. Personally, I know that Neti is a bit difficult to understand for the first time, but once you understand how it works, this is the best NIO Framework in Java. IMO
Comments
Post a Comment