Erratic message reception when more than 1 client
Sergey S
sergey.saleev at gmail.com
Wed Jan 13 06:37:26 EST 2010
Hi
it looks like you are using same pipeline for all channels, it's wrong way
for a pipeline with encoders/decoders. You should use PipelineFactory like
in Telnet example:
32 public class TelnetServer {
33
34 public static void main(String[] args) throws Exception {
35 // Configure the server.
36 ServerBootstrap bootstrap = new ServerBootstrap(
37 new NioServerSocketChannelFactory(
38 Executors.newCachedThreadPool(),
39 Executors.newCachedThreadPool()));
40
41 TelnetServerHandler handler = new TelnetServerHandler();
42 bootstrap.setPipelineFactory(new
TelnetPipelineFactory(handler));
43
44 // Bind and start to accept incoming connections.
45 bootstrap.bind(new InetSocketAddress(8080));
46 }
47 }
wiradikusuma wrote:
>
> Hi guys,
>
> I'm experiencing erratic message reception when there are more than one
> client connected to my Netty-based TCP server.
>
> The client is a dummy MINA client sending 1KB XML string 5000 times:
> -- client ----------------------------------------------
> for 1 to 5000 { session.write(something) }
> --------------------------------------------------------
>
> The server looks like this:
> -- Spring ----------------------------------------------
> <bean id="executor" class="...ThreadPoolTaskExecutor" scope="prototype">
> <property name="corePoolSize" value="10"/>
> <property name="maxPoolSize" value="5000"/>
> </bean>
> --------------------------------------------------------
>
> -- connection initiation -------------------------------
> ChannelFactory cf = new OioServerSocketChannelFactory(executor, executor);
> ServerBootstrap bootstrap = new ServerBootstrap(cf);
>
> ChannelPipeline pipeline = bootstrap.getPipeline();
> pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
> Delimiters.lineDelimiter()));
> pipeline.addLast("decoder", new StringDecoder());
> pipeline.addLast("encoder", new StringEncoder());
> pipeline.addLast("handler", clientHandler);
>
> bootstrap.setOption("child.tcpNoDelay", true);
> bootstrap.setOption("child.keepAlive", true);
> bootstrap.setOption("reuseAddress", true);
> bootstrap.bind(new InetSocketAddress(serverPort));
> --------------------------------------------------------
>
> -- handler ---------------------------------------------
> @ChannelPipelineCoverage("all")
> class ClientHandler extends SimpleChannelHandler {
> channelConnected(...) {
> ctx.setAttachment(new ClientXml());
> }
>
> messageReceived(...) {
> Channel channel = event.getChannel();
> ClientXml data = (ClientXml) context.getAttachment();
> data.addXmlPart((String) event.getMessage());
>
> final String xml = data.getNextXML();
> if (xml != null) {
> executor.execute(new Runnable() {
> public void run() {
> // do something useful
> }
> }
> }
> }
> --------------------------------------------------------
>
> When only one client connected to the server, everything is OK.
> All messages received correctly, all XMLs logged correctly.
> But when there are more than one, my log starts to look like this:
>
> --------------------------------------------------------
> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
> version='1.0' encoding='UTF-8' standalone='yes'?> ... continue until
> unlimited
> --------------------------------------------------------
>
> Any idea what happens and what should I do?
>
--
View this message in context: http://n2.nabble.com/Erratic-message-reception-when-more-than-1-client-tp4343987p4345095.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list