HTTP 1.1 Persistent Connections using Sockets in Java

前端 未结 5 1220
无人共我
无人共我 2020-12-30 16:45

Let\'s say I have a java program that makes an HTTP request on a server using HTTP 1.1 and doesn\'t close the connection. I make one request, and read all data returned from

5条回答
  •  醉梦人生
    2020-12-30 17:11

    Writing a simple http/1.1 client respecting the RFC is not such a difficult task. To solve the problem of the blocking i/o access where reading a socket in java, you must use java.nio classes. SocketChannels give the possibility to perform a non-blocking i/o access.

    This is necessary to send HTTP request on a persistent connection.

    Furthermore, nio classes will give better performances.

    My stress test give to following results :

    • HTTP/1.0 (java.io) -> HTTP/1.0 (java.nio) = +20% faster

    • HTTP/1.0 (java.io) -> HTTP/1.1 (java.nio with persistent connection) = +110% faster

提交回复
热议问题