全部產品
Search
文件中心

Container Service for Kubernetes:ossfs2.0 用戶端壓測效能

更新時間:May 07, 2025

本文介紹ossfs 2.0在不同情境下的效能,包括檔案的讀寫速度、並發情境下的表現等,以便提供準確的效能參考,協助您更好地選擇和使用ossfs 2.0進行相關業務操作。

測試環境

  • 硬體環境

    • 執行個體規格:ecs.g7.32xlarge (128vCPU 512GiB)。

    • vCPU:128 vCPU。

    • 記憶體:512 GiB。

  • 軟體環境

    • 作業系統:Alibaba Cloud Linux 3.2104 LTS 64位。

    • 核心版本:5.10.134-18.al8.x86_64。

    • ossfs版本:ossfs 2.0.0beta、ossfs 1.91.4。

掛載配置

假設OSS儲存卷在容器中的掛載路徑為/mnt/oss

  • ossfs 2.0儲存卷

    本次測試在掛載時,追加以下otherOpts,指定上傳檔案分區大小為33554432 Bytes。

    upload_buffer_size=33554432
  • ossfs 1.0儲存卷

    本次測試在掛載時,追加以下otherOpts,同時開啟直讀模式與緩衝最佳化功能。

    -o direct_read -o readdir_optimize

測試情境

使用ossfs 2.0.0beta和ossfs 1.91.4掛載Bucket儲存空間後,運用FIO測試載入器,分別針對ossfs 2.0與ossfs 1.0的基本讀寫能力展開測試。具體測試情境及結果如下。

單線程順序直寫100 GB檔案

說明

ossfs 1.0的寫入效能受磁碟效能制約。

  • 測試命令

    使用FIO工具,執行名為file-100G的單次單線程直接寫測試工作,塊大小為1 MB,寫入總量100 GB的資料到/mnt/oss/fio_direct_write目錄並輸出測試結果。

    fio --name=file-100G --ioengine=libaio --rw=write --bs=1M --size=100G --numjobs=1 --direct=1 --directory=/mnt/oss/fio_direct_write --group_reporting
  • 測試結果

    ossfs版本

    頻寬

    CPU核心佔用率(單個核心滿載為100%)

    峰值記憶體

    ossfs 2.0

    2.2 GB/s

    207%

    2167 MB

    ossfs 1.0

    118 MB/s

    5%

    15 MB

單線程順序讀取100 GB檔案

  • 測試命令

    清除系統頁面緩衝,再用FIO工具對/mnt/oss/fio_direct_write目錄下的100 GB檔案進行單線程、塊大小1 MB的順序讀測試並輸出測試結果。

    echo 1 > /proc/sys/vm/drop_caches
    fio --name=file-100G --ioengine=libaio --direct=1 --rw=read --bs=1M --directory=/mnt/oss/fio_direct_write --group_reporting --numjobs=1
  • 測試結果

    ossfs版本

    頻寬

    CPU核心佔用率(單個核心滿載為100%)

    峰值記憶體

    ossfs 2.0

    3.0 GB/s

    378%

    1617 MB

    ossfs 1.0

    355 MB/s

    50%

    400 MB

多線程順序讀取100 GB檔案

  • 產生測試檔案

    在掛載目錄/mnt/oss/fio下建立4個100 GB的檔案用於多線程並發測試。

    fio --name=file-100g --ioengine=libaio --direct=1 --iodepth=1 --numjobs=4 --nrfiles=1 --rw=write --bs=1M  --size=100G --group_reporting --thread --directory=/mnt/oss/fio
  • 測試命令

    清除系統頁面緩衝,再用FIO工具通過4個並發線程對/mnt/oss/fio目錄下的4個100 GB檔案進行1 MB塊大小的30秒讀取測試,並輸出測試結果。

    echo 1 > /proc/sys/vm/drop_caches
    fio --name=file-100g --ioengine=libaio --direct=1 --iodepth=1 --numjobs=4 --nrfiles=1 --rw=read --bs=1M  --size=100G --group_reporting --thread --directory=/mnt/oss/fio --time_based --runtime=30
  • 測試結果

    ossfs版本

    頻寬

    CPU核心佔用率(單個核心滿載為100%)

    峰值記憶體

    ossfs 2.0

    7.1 GB/s

    1187%

    6.2 GB

    ossfs 1.0

    1.4 GB/s

    210%

    1.6 GB

128線程並發讀10萬128 KB檔案

說明

OSS預設提供10000的QPS限制。若要達到測試結果中的效能指標,需要確保測試帳號的QPS不會被其他業務佔用。

  • 測試步驟

    1. 建立名為rw-bench.go的Go語言程式。

      此程式具備兩項核心功能。其一,它能夠並發地在目標檔案目錄下建立若干個大小相同的檔案;其二,它可以並發讀取目標檔案目錄下的所有檔案,將這些檔案分配給n個線程進行讀取操作,並且記錄最終的頻寬資料。

      程式碼範例

      package main
      
      import (
      	"flag"
      	"fmt"
      	"io"
      	"log"
      	"os"
      	"path/filepath"
      	"sync"
      	"time"
      )
      
      var dir = flag.String("dir", "", "work dir")
      var threads = flag.Int("threads", 128, "concurrency threads count")
      var isWrite = flag.Bool("write", false, "test write files")
      var fileSize = flag.Int64("file-size-KB", 128, "file size in KBytes")
      var fileCount = flag.Int("file-count", 0, "file count")
      
      type fileInfo struct {
      	Name string
      	Size int64
      }
      
      func getFileList(dir string, isWrite bool) []fileInfo {
      	var files []fileInfo
      
      	if isWrite {
      		for i := 0; i < *fileCount; i++ {
      			files = append(files, fileInfo{
      				Name: fmt.Sprintf("%v/%v.dat", dir, i),
      				Size: *fileSize * 1024,
      			})
      		}
      	} else {
      		err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
      			if err != nil {
      				return err
      			}
      			if !info.IsDir() {
      				files = append(files, fileInfo{
      					Name: path,
      					Size: info.Size(),
      				})
      			}
      			return nil
      		})
      
      		if err != nil {
      			log.Fatalf("Error walking the path %v: %v\n", dir, err)
      		}
      	}
      
      	return files
      }
      
      func worker(taskChan <-chan fileInfo, wg *sync.WaitGroup, bytesChan chan<- int64, isWrite bool) {
      	defer wg.Done()
      	buffer := make([]byte, 1024*1024)
      
      	for fInfo := range taskChan {
      		var fd *os.File
      		var err error
      		if isWrite {
      			fd, err = os.OpenFile(fInfo.Name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
      			if err != nil {
      				fmt.Printf("Failed to create/open %v with %v\n", fInfo.Name, err)
      				continue
      			}
      		} else {
      			fd, err = os.OpenFile(fInfo.Name, os.O_RDONLY, 0)
      			if err != nil {
      				fmt.Printf("Failed to open %v with %v\n", fInfo.Name, err)
      				continue
      			}
      		}
      
      		offset := int64(0)
      		var totalBytes int64
      		for offset < fInfo.Size {
      			var n int
      
      			if offset+int64(len(buffer)) > fInfo.Size {
      				buffer = buffer[:fInfo.Size-offset]
      			}
      
      			if isWrite {
      				n, err = fd.WriteAt(buffer, offset)
      				if err != nil {
      					fmt.Printf("Failed to write file %v at %v, with %v\n", fInfo.Name, offset, err)
      					break
      				}
      			} else {
      				n, err = fd.ReadAt(buffer, offset)
      				if err != nil && err != io.EOF {
      					fmt.Printf("Failed to read file %v at %v, with %v\n", fInfo.Name, offset, err)
      					break
      				}
      			}
      
      			totalBytes += int64(n)
      			offset += int64(n)
      		}
      
      		fd.Close()
      		bytesChan <- totalBytes
      	}
      }
      
      func doBench(dir string, isWrite bool) {
      	files := getFileList(dir, isWrite)
      	var wg sync.WaitGroup
      
      	if isWrite {
      		fmt.Printf("start write bench with %v files\n", len(files))
      	} else {
      		fmt.Printf("start read bench with %v files\n", len(files))
      	}
      
      	taskChan := make(chan fileInfo, 1024)
      
      	go func(taskChan chan<- fileInfo) {
      		for _, fInfo := range files {
      			taskChan <- fInfo
      		}
      		close(taskChan)
      	}(taskChan)
      
      	bytesChan := make(chan int64, 1024)
      	for i := 0; i < *threads; i++ {
      		wg.Add(1)
      		go worker(taskChan, &wg, bytesChan, isWrite)
      	}
      
      	st := time.Now()
      	go func() {
      		wg.Wait()
      		close(bytesChan)
      	}()
      
      	var totalBytes int64
      	for bytes := range bytesChan {
      		totalBytes += bytes
      	}
      
      	ed := time.Now()
      	duration := ed.Sub(st)
      	throughput := float64(totalBytes) / (float64(duration.Nanoseconds()) / 1e9)
      
      	fmt.Printf("Total time: %v\n", duration)
      	if isWrite {
      		fmt.Printf("Write throughput: %.2f MBytes/s\n", throughput/1000/1000)
      	} else {
      		fmt.Printf("Read throughput: %.2f MBytes/s\n", throughput/1000/1000)
      	}
      }
      
      func main() {
      	flag.Parse()
      
      	workdir := *dir
      	if workdir == "" {
      		flag.Usage()
      		os.Exit(1)
      	}
      
      	if _, err := os.Stat(workdir); err != nil {
      		fmt.Printf("Failed to access %v with %v\n", workdir, err)
      		os.Exit(1)
      	}
      
      	doBench(workdir, *isWrite)
      }
      
    2. 編譯rw-bench.go程式檔案。

      go build rw-bench.go
    3. 在已掛載到本地的OSSBucket目錄中,建立100000個128 KB大小的檔案。

      mkdir -p <已掛載測試檔案夾路徑> && ./rw-bench --dir <已掛載測試檔案夾路徑> --file-size-KB 128 --file-count 100000 --write
    4. 清除系統頁面緩衝並執行該程式,連續開展5次測試。在服務端時延趨於穩定後取穩態測試資料。

      echo 1 > /proc/sys/vm/drop_caches
      ./rw-bench --dir <已掛載測試檔案夾路徑> --threads 128
  • 測試結果

    ossfs版本

    頻寬

    CPU核心佔用率(單個核心滿載為100%)

    峰值記憶體

    ossfs 2.0

    1 GB/s

    247%

    212 MB

    ossfs 1.0

    3.5 MB/s

    3%

    200 MB