分类 默认分类 下的文章

关于 Tomcat HTTP connector 的具体实现及使用

以 tomcat 8 为例, 有4个 http protocol 实现:

  1. org.apache.coyote.http11.Http11Protocol - blocking Java connector
  2. org.apache.coyote.http11.Http11NioProtocol - non blocking Java NIO connector
  3. org.apache.coyote.http11.Http11Nio2Protocol - non blocking Java NIO2 connector
  4. org.apache.coyote.http11.Http11AprProtocol - the APR/native connector.

如果配置里面没有设置这个 protocol 的值, 是有个自动选择机制:

Sets the protocol to handle incoming traffic. The default value is
HTTP/1.1 which uses an auto-switching mechanism to select either a non
blocking Java NIO based connector or an APR/native based connector. If
the PATH (Windows) or LD_LIBRARY_PATH (on most unix systems)
environment variables contain the Tomcat native library, the
APR/native connector will be used. If the native library cannot be
found, the non blocking Java based connector will be used. Note that
the APR/native connector has different settings for HTTPS than the
Java connectors.

nio 和 nio2 有什么区别?

Apr/native 是什么?

refer:
https://tomcat.apache.org/tomcat-8.0-doc/config/http.html#Connector_Comparison

关于 Java Socket 和 TCP 连接的相关问题

这个问答解释了 Socket 和 TCP 的 level 问题.
https://stackoverflow.com/questions/10240694/java-socket-api-how-to-tell-if-a-connection-has-been-closed

这篇文章介绍了 Socket close() 和 TCP 的 FIN, RST 的相关问题.
https://docs.oracle.com/javase/8/docs/technotes/guides/net/articles/connection_release.html

查看 JDK 源代码: SocketInputStream 和 SocketOutputStream 的 read 和 write 方法, 可以看到只有在 read 和 write 的时候才能知道这个 tcp 连接的状态.

对于 NIO 可以更快的知道这个消息.

HttpClient 库的介绍中, 有关于如何关掉 idle 和 expired 的连接问题:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e373

tomcat 连接数

the crux of the solution is to avoid too much queuing of requests at multiple points (OS and tomcat threads) and fail fast (return http status 503) as soon the application’s maximum capacity is reached

refer:
https://blog.insightdatascience.com/learning-about-the-http-connection-keep-alive-header-7ebe0efa209d
https://medium.com/netflix-techblog/tuning-tomcat-for-a-high-throughput-fail-fast-system-e4d7b2fc163f
https://stackoverflow.com/questions/20763999/how-does-http-keep-alive-work

关于 linux rsync & scp 命令

$ rsync --progress accessa.log.7.gz xiatian@test1.tianxiaohui.com:/home/xiatian

$ scp username@from_host:file.txt /local/directory/
$ scp file.txt username@to_host:/remote/directory/
$ scp -r username@from_host:/remote/directory/ /local/directory/ //copy目录
$ scp username@from_host:/remote/directory/file.txt username@to_host:/remote/directory/