At last i modified the code as below and still i see ~50K requests/sec ..
public class HelloWorldServer {
public static void main(final String[] args) {
Undertow server = Undertow.builder().addHttpListener(8009, "localhost").setHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
if (exchange.getRequestMethod().equals(Methods.POST)) {
BufferedReader reader = null;
StringBuilder builder = new StringBuilder();
try {
exchange.startBlocking();
reader = new BufferedReader(new InputStreamReader(exchange.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
String body = builder.toString();
System.out.println("Req Body ==> " + body);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("SUCCESS");
} else {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("FAILURE");
}
}
}).build();
server.start();
}
}