背景
文件存儲(Cloud File Storage,CFS)支持 NFS v3.0 及 NFS v4.0 協議, 其中 NFS v3.0 是 NFS 協議較早期版本,兼容 Windows 客戶端;NFS v4.0 協議為稍后期版本,支持文件鎖等功能。
客戶端現象
在大量小文件或者大小文件混合場景下,用戶在容器服務(Tencent Kubernetes Engine,TKE)或者雲服務器(Cloud Virtual Machine,CVM)等客戶端使用 NFS v4.0 協議掛載 CFS,可能在應用運行一段時候后出現:客戶端負載居高不下,無限累加,業務讀取數據慢或無響應,但是業務進程的 CPU 使用率並不是很高的情況。
問題原因
上述問題出現的主要原因是 NFS v4.0 協議的限制, 客戶端使用 NFS v4.0 同時大批量讀寫文件時由於協議的 OPEN/CLOSE 操作為串行化,因此在客戶端大量操作請求並發情況下,協議處理會形成阻塞。具體協議描述如下:
- There is a limitation to the Linux NFS4.0 client implementation that an "open_owner" is mapped to a userid. This results in a bottleneck if one user opens and closes a lot of files in a short period of time. Each OPEN / CLOSE operation has to wait for a sequence id, which essentially serializes each OPEN / CLOSE request. If an NFS server's response time for OPEN / CLOSE requests increases due to some secondary load or complication, this NFS4 client limitation can become pronounced, and in some cases, cause an unresponsive machine.
- The NFS4.1 protocol addresses the limitation of serialization of OPENs per open_owner. For more information, see RFC 5661 Section 9.10
使用優化
如果業務應用存在大量小文件的場景,或者並發操作文件數量巨大,推薦客戶端使用 NFS v3.0 協議掛載。以下為規避大量小文件及大並發請求下客戶端高負載的問題的方法。
雲服務器等客戶端掛載方法
進入 文件存儲 控制台,打開待掛載的文件系統詳情中的掛載點信息,找到如下圖的 NFS v3.0 掛載命令。使用該掛載命令掛載文件系統即可。
容器客戶端掛載方法
容器可以通過 pv/pvc 的方式使用 NFS v3.0 協議進行掛載,參考配置如下。
apiVersion: v1 kind: PersistentVolume metadata: name: cfs-test-pv spec: accessModes: - ReadWriteMany capacity: storage: 9000Gi mountOptions: - vers=3 - nolock - proto=tcp - noatime - nodiratime - noexec - hard - rsize=524288 - wsize=524288 nfs: path: /[cfs-id]/[mount-path]/ server: [cfs-server-ip] persistentVolumeReclaimPolicy: Retain storageClassName: cfs-test-pv volumeMode: Filesystem --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: cfs-test-pvc namespace: default spec: accessModes: - ReadWriteMany resources: requests: storage: 9000Gi storageClassName: cfs-test-pv volumeMode: Filesystem volumeName: cfs-test-pv
引用:
https://cloud.tencent.com/document/product/582/46359