Hero Image
Tuning EMQX to Scale to One Million Concurrent Connection on Kubernetes

Tuning EMQX to Scale to One Million Concurrent Connection on Kubernetes Performance Tuning (Linux) 矽谷牛的耕田筆記 Linux Kernel Tuning node level, basically the non-namespaced sysctls # Sets the maximum number of file handles allowed by the kernel sysctl -w fs.file-max=2097152 # Sets the maximum number of open file descriptors that a process can have sysctl -w fs.nr_open=2097152 namespaced sysctls # Sets the maximum number of connections that can be queued for acceptance by the kernel. sysctl -w net.core.somaxconn=32768 # Sets the maximum number of SYN requests that can be queued by the kernel sysctl -w net.ipv4.tcp_max_syn_backlog=16384 # Setting the minimum, default and maximum size of TCP Buffer sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216' sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216' # Setting Parameters for TCP Connection Tracking sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=30 # Controls the maximum number of entries in the TCP time-wait bucket table sysctl -w net.ipv4.tcp_max_tw_buckets=1048576 # Controls Timeout for FIN-WAIT-2 Sockets: sysctl -w net.ipv4.tcp_fin_timeout=15 There are some more namespaced sysctls that will improve the performance but because of an active issue we are not able to set them on the container level # Sets the size of the backlog queue for the network device sysctl -w net.core.netdev_max_backlog=16384 # Amount of memory that is allocated for storing incoming and outgoing data for a socket sysctl -w net.core.rmem_default=262144 sysctl -w net.core.wmem_default=262144 # Setting the maximum amount of memory for the socket buffers sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.wmem_max=16777216 sysctl -w net.core.optmem_max=16777216 Erlang VM Tuning ## Erlang Process Limit node.process_limit = 2097152 ## Sets the maximum number of simultaneously existing ports for this system node.max_ports = 2097152 EMQX Broker Tuning # Other configuration… EMQX_LISTENER__TCP__EXTERNAL: "0.0.0.0:1883" EMQX_LISTENER__TCP__EXTERNAL__ACCEPTORS: 64 EMQX_LISTENER__TCP__EXTERNAL__MAX_CONNECTIONS: 1024000

Hero Image
【理解 Cilium 系列文章】(一) 初識 Cilium

【理解 Cilium 系列文章】(一) 初識 Cilium 當前 k8s Service 負載均衡的實現現狀 在 Cilium 出現之前, Service 由 kube-proxy 來實現,實現方式有 userspace , iptables , ipvs 三種模式。 Userspace 當前模式下,kube-proxy 作為反向代理,監聽隨機端口,通過 iptables 規則將流量重定向到代理端口,再由 kube-proxy 將流量轉發到 後端 pod。Service 的請求會先從用户空間進入內核 iptables,然後再回到用户空間,代價較大,性能較差。 Iptables 存在的問題: 1.可擴展性差。隨着 service 數據達到數千個,其控制面和數據面的性能都會急劇下降。原因在於 iptables 控制面的接口設計中,每添加一條規則,需要遍歷和修改所有的規則,其控制面性能是 O(n²) 。在數據面,規則是用鏈表組織的,其性能是 O(n) 2.LB 調度算法僅支持隨機轉發 Ipvs 模式 IPVS 是專門為 LB 設計的。它用 hash table 管理 service,對 service 的增刪查找都是 O(1)的時間複雜度。不過 IPVS 內核模塊沒有 SNAT 功能,因此借用了 iptables 的 SNAT 功能。 IPVS 針對報文做 DNAT 後,將連接信息保存在 nf_conntrack 中,iptables 據此接力做 SNAT。該模式是目前 Kubernetes 網絡性能最好的選擇。但是由於 nf_conntrack 的複雜性,帶來了很大的性能損耗。騰訊針對該問題做過相應的優化 【繞過 conntrack,使用 eBPF 增強 IPVS 優化 K8s 網絡性能】

Hero Image
Day 28 - Kubernetes 第三方好用工具介紹

Day 28 - Kubernetes 第三方好用工具介紹 $ kubectl get pods NAME READY STATUS RESTARTS AGE ithome-6564f65698-947rv 1/1 Running 0 84s ithome-6564f65698-fglr9 1/1 Running 0 84s ithome-6564f65698-k5wtg 1/1 Running 0 84s ithome-6564f65698-rrvk4 1/1 Running 0 84s ithome-6564f65698-zhwlj 1/1 Running 0 84s Stern/Kail 創建出來的 Pod 名稱上面都會有一些不好閱讀的亂數 如果使用 kubectl 來觀察個別 Pod 的 log 就必須要於不同的 pod 之間來回切換 這方面的工具滿多的,譬如 Stern, Kube-tail, Kail 等都可以 上述範例會有五個 pod,而且這五個 pod 的名稱都是 ithome 開頭,因此我可以直接用 stern ithom 的方式來抓取這些 pod 的資訊,結果如下圖 $ stern ithome ... ithome-6564f65698-zhwlj netutils Hello! 369 secs elapsed... ithome-6564f65698-fglr9 netutils Hello! 369 secs elapsed... ithome-6564f65698-947rv netutils Hello! 367 secs elapsed... ithome-6564f65698-k5wtg netutils Hello! 368 secs elapsed... ithome-6564f65698-rrvk4 netutils Hello! 369 secs elapsed... ithome-6564f65698-zhwlj netutils Hello! 370 secs elapsed... ithome-6564f65698-fglr9 netutils Hello! 370 secs elapsed... ithome-6564f65698-947rv netutils Hello! 368 secs elapsed... ithome-6564f65698-k5wtg netutils Hello! 370 secs elapsed... ithome-6564f65698-rrvk4 netutils Hello! 370 secs elapsed... ithome-6564f65698-zhwlj netutils Hello! 371 secs elapsed... ithome-6564f65698-fglr9 netutils Hello! 371 secs elapsed... ithome-6564f65698-947rv netutils Hello! 369 secs elapsed... ithome-6564f65698-k5wtg netutils Hello! 371 secs elapsed... ithome-6564f65698-rrvk4 netutils Hello! 371 secs elapsed... ithome-6564f65698-zhwlj netutils Hello! 372 secs elapsed... ithome-6564f65698-fglr9 netutils Hello! 372 secs elapsed... ^C K9S 過往總是透過 kubectl 指令於各個資源,各 namespace 間切來切去,特別是要使用 exec, get, describe, logs, delete 等指令時,常常打的手忙腳亂或是覺得心累,有這種困擾的人可以考慮使用看看 k9s 這個工具