I implemented an API using Jersey Resources and environment.servlets().addServlet(newServlet)
to see which one would be faster.
Both do the exact same thing. But when I run AB benchmarking on the two implementations, using Jersey Resource works fine but with Servlet I get apr_socket_recv: Connection reset by peer (54)
.
This only happens when hitting with concurrent requests:
ab -n 10000 -c 100 -k -T application/binary -p req.bin http://localhost:8142/
Any idea why Servlet would have this issue? (the reason I want to use servlet is the data I am posting is raw binary and its easier to handle it there using the Input/Output Stream.
I found the reason. It was due to Keep Alive connections, I needed to set the Content-Length header in the response.
response.setContentLength(out.len());
response.getOutputStream().write(out.get(), 0, out.len());
response.getOutputStream().flush();
And not call response.getOutputStream().close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.