aggregation - Netty 4.0.26-FINAL client to send multiple small messages and sync -
i have client needs send alot of small messages server (< 8k each messages), single thread can push 1.2 million of messages 1 after other without delay in between reception of messages.
how configure netty client "buffer" write flushes automatically @ given buffer size , doesn't create me oom errors ?
as simple example, let's want send content of file, line line simulate reception of such messages.
eventloopgroup group = new nioeventloopgroup(); try { bootstrap b = new bootstrap(); b.group(group).channel(niosocketchannel.class).handler(new channelinitializer<channel>() { @override protected void initchannel(channel ch) throws exception { ch.pipeline().addlast(new stringencoder()); } }); // start connection attempt. channel ch = b.connect("localhost", 6000).sync().channel(); channelfuture lastwritefuture = null; bufferedreader in = new bufferedreader(new inputstreamreader(new fileinputstream(new file( "data.txt")))); int = 0; while (true) { // simulates incoming data string line = in.readline(); if (line == null) { break; } lastwritefuture = ch.write(line + '\n'); // todo : investigate why need this, otherwise throws oom errors... if (i++ % 10000 == 0) { ch.flush(); lastwritefuture.awaituninterruptibly(); } } // part here because it's simulation, there no notion of "end of data" in our normal process, it's continuous send of data. ch.flush(); // wait until messages flushed before closing channel. if (lastwritefuture != null) { lastwritefuture.sync(); } } { // connection closed automatically on shutdown. group.shutdowngracefully(); }
what i'm trying figure out, how can make continuous write without need flush @ every x messages ?
i've seen norman's maurer talk voidchannelpromise, can't used here i'll need sslhandler in pipeline well.
do need , how implement throttling ?
also, netty 3 had bufferedwritehandler doesn't seem exist anymore in netty 4.0, overlooking option set "enable" buffering ?
any example achieve ?
thanks,
Comments
Post a Comment