From 7f7e88e2c47a93e5cca53e2f7484ce48fde64e66 Mon Sep 17 00:00:00 2001 From: Warren Date: Wed, 24 Jun 2026 11:35:17 +0800 Subject: [PATCH] Add SMB benchmark script SMB Performance Benchmark Script: - Tests: upload, download, directory listing, delete - Supports macOS smbutil and Linux smbclient - Custom port support (4445) - Test files: 1MB, 10MB, 50MB, 100MB Usage: chmod +x scripts/smb_benchmark.sh ./scripts/smb_benchmark.sh Note: macOS smbutil doesn't support custom ports Use port 445 or Docker/Linux smbclient for full testing --- scripts/smb_benchmark.sh | 168 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100755 scripts/smb_benchmark.sh diff --git a/scripts/smb_benchmark.sh b/scripts/smb_benchmark.sh new file mode 100755 index 0000000..4e29bf2 --- /dev/null +++ b/scripts/smb_benchmark.sh @@ -0,0 +1,168 @@ +#!/bin/bash +# SMB Performance Benchmark +# Tests: upload, download, directory listing, rename, delete +# Requires: smbutil (macOS) or smbclient (Linux) + +set -e + +SMB_SERVER="127.0.0.1" +SMB_PORT="4445" +SMB_SHARE="markbase" +SMB_USER="demo" +SMB_PASS="demo123" +TEST_DIR="/tmp/smb_benchmark" + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +echo "================================================" +echo "SMB Performance Benchmark" +echo "================================================" +echo "" + +# Check SMB server is running +echo "Checking SMB server status..." +if ! nc -z $SMB_SERVER $SMB_PORT 2>/dev/null; then + echo "${RED}ERROR: SMB server not running on port $SMB_PORT${NC}" + echo "${YELLOW}Start SMB server first:${NC}" + echo " cargo run --bin markbase-core --features smb-server -- smb-start --port $SMB_PORT --share-name $SMB_SHARE --root /tmp/smb_test --user $SMB_USER:$SMB_PASS" + exit 1 +fi +echo "${GREEN}SMB server is running${NC}" +echo "" + +# Setup test directory +rm -rf "$TEST_DIR" +mkdir -p "$TEST_DIR" +cd "$TEST_DIR" + +# Generate test files +echo "Generating test files..." +dd if=/dev/urandom of=file_1mb.bin bs=1M count=1 2>/dev/null +dd if=/dev/urandom of=file_10mb.bin bs=1M count=10 2>/dev/null +dd if=/dev/urandom of=file_50mb.bin bs=1M count=50 2>/dev/null +dd if=/dev/urandom of=file_100mb.bin bs=1M count=100 2>/dev/null +echo "${GREEN}Test files generated${NC}" +echo "" + +# Detect OS and choose SMB client +OS=$(uname -s) +if [ "$OS" = "Darwin" ]; then + SMB_CLIENT="smbutil" + SMB_MOUNT="/Volumes/smb_benchmark" +else + SMB_CLIENT="smbclient" +fi + +echo "Using SMB client: $SMB_CLIENT (OS: $OS)" +echo "" + +# macOS smbutil tests +if [ "$OS" = "Darwin" ]; then + echo "=== Test 1: SMB Share Status ===" + smbutil statshares -a 2>/dev/null || echo "${YELLOW}No active SMB shares${NC}" + echo "" + + echo "=== Test 2: SMB Share View ===" + START=$(date +%s.%N) + smbutil view "//$SMB_USER@$SMB_SERVER" -g "$SMB_PASS" 2>/dev/null || echo "${YELLOW}Share view failed (expected on custom port)${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + echo "${GREEN}Share view: ${ELAPSED}s${NC}" + echo "" + + echo "=== Test 3: SMB Mount ===" + # Note: macOS smbutil doesn't support custom port, need mount_smbfs + echo "${YELLOW}mount_smbfs requires standard port 445${NC}" + echo "${YELLOW}Testing with smbutil instead${NC}" + echo "" + + echo "=== Test 4: SMB Tree Connect ===" + # Test tree connect via smbutil + START=$(date +%s.%N) + smbutil tree "//$SMB_SERVER/$SMB_SHARE" -g "$SMB_PASS" -u "$SMB_USER" 2>/dev/null || echo "${YELLOW}Tree connect failed (expected on custom port)${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + echo "${GREEN}Tree connect: ${ELAPSED}s${NC}" + echo "" +fi + +# Linux smbclient tests +if [ "$OS" = "Linux" ]; then + echo "=== Test 1: SMB Share Listing ===" + START=$(date +%s.%N) + smbclient -L "$SMB_SERVER" -U "$SMB_USER%$SMB_PASS" -p $SMB_PORT 2>/dev/null || echo "${YELLOW}Share listing failed${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + echo "${GREEN}Share listing: ${ELAPSED}s${NC}" + echo "" + + echo "=== Test 2: SMB Directory Listing ===" + START=$(date +%s.%N) + smbclient "//$SMB_SERVER/$SMB_SHARE" -U "$SMB_USER%$SMB_PASS" -p $SMB_PORT -c "ls" 2>/dev/null || echo "${YELLOW}Directory listing failed${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + echo "${GREEN}Directory listing: ${ELAPSED}s${NC}" + echo "" + + echo "=== Test 3: SMB Upload 1MB ===" + START=$(date +%s.%N) + smbclient "//$SMB_SERVER/$SMB_SHARE" -U "$SMB_USER%$SMB_PASS" -p $SMB_PORT -c "put file_1mb.bin" 2>/dev/null || echo "${YELLOW}Upload failed${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + SPEED=$(echo "1 / $ELAPSED" | bc) + echo "${GREEN}Upload 1MB: ${ELAPSED}s (${SPEED} MB/s)${NC}" + echo "" + + echo "=== Test 4: SMB Upload 10MB ===" + START=$(date +%s.%N) + smbclient "//$SMB_SERVER/$SMB_SHARE" -U "$SMB_USER%$SMB_PASS" -p $SMB_PORT -c "put file_10mb.bin" 2>/dev/null || echo "${YELLOW}Upload failed${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + SPEED=$(echo "10 / $ELAPSED" | bc) + echo "${GREEN}Upload 10MB: ${ELAPSED}s (${SPEED} MB/s)${NC}" + echo "" + + echo "=== Test 5: SMB Upload 100MB ===" + START=$(date +%s.%N) + smbclient "//$SMB_SERVER/$SMB_SHARE" -U "$SMB_USER%$SMB_PASS" -p $SMB_PORT -c "put file_100mb.bin" 2>/dev/null || echo "${YELLOW}Upload failed${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + SPEED=$(echo "100 / $ELAPSED" | bc) + echo "${GREEN}Upload 100MB: ${ELAPSED}s (${SPEED} MB/s)${NC}" + echo "" + + echo "=== Test 6: SMB Download 100MB ===" + START=$(date +%s.%N) + smbclient "//$SMB_SERVER/$SMB_SHARE" -U "$SMB_USER%$SMB_PASS" -p $SMB_PORT -c "get file_100mb.bin" 2>/dev/null || echo "${YELLOW}Download failed${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + SPEED=$(echo "100 / $ELAPSED" | bc) + echo "${GREEN}Download 100MB: ${ELAPSED}s (${SPEED} MB/s)${NC}" + echo "" + + echo "=== Test 7: SMB Delete ===" + START=$(date +%s.%N) + smbclient "//$SMB_SERVER/$SMB_SHARE" -U "$SMB_USER%$SMB_PASS" -p $SMB_PORT -c "del file_1mb.bin; del file_10mb.bin; del file_100mb.bin" 2>/dev/null || echo "${YELLOW}Delete failed${NC}" + END=$(date +%s.%N) + ELAPSED=$(echo "$END - $START" | bc) + echo "${GREEN}Delete 3 files: ${ELAPSED}s${NC}" + echo "" +fi + +# Cleanup +cd / +rm -rf "$TEST_DIR" +echo "${GREEN}Cleanup complete${NC}" + +echo "" +echo "================================================" +echo "SMB Performance Benchmark Complete" +echo "================================================" +echo "" +echo "${YELLOW}Note: macOS smbutil doesn't support custom ports${NC}" +echo "${YELLOW}For full SMB testing on macOS, use port 445${NC}" +echo "${YELLOW}Or use Docker/Linux smbclient${NC}" \ No newline at end of file