使用 scp 估计网络 I/O 速度

发布于 2024-11-27 05:27:23 字数 148 浏览 1 评论 0 原文

我想粗略估计两台 Linux 服务器之间的网络 I/O 速度。问题是我没有 sudo 访问服务器的权限。所以我尝试使用 scp 在两台服务器之间传输 1GB 文件。我想通过加密,速度会有所下降。我应该预期减速多少?服务器管理员也可以限制 scp 带宽使用吗?我怎么知道它是否有上限?

I want to have a rough estimate of the network I/O speed between two linux servers. The problem is that I don't have sudo access to the servers. So I tried transferring a 1GB file between the two servers using scp. I suppose that with the encryption there will be some slowdown. How much slowdown should I be expecting? Also can the scp bandwidth usage be capped by the server admin? How do I know if it is capped?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

平定天下 2024-12-04 05:27:23

加密通常不是 scp 传输的瓶颈,但您可以使用 ftp 代替。

我通常的方法是使用这个命令在某个端口上的任何目录上打开一个Python Web服务器,

python -m SimpleHTTPServer 8000  # python 2
python -m http.server 8000 # python 3

而在另一端只需使用wget来下载它

wget http://[ip address]:8000/[some big file]

任何网络活动都可能受到服务器管理员的限制,通常的指标是你的速度保持在一个很好的稳定水平(例如500KB/s)

The encryption is normally not the bottleneck in a scp transfer, but you can use ftp instead.

My usual way is to open a Python web server on any directory on a certain port using this single command

python -m SimpleHTTPServer 8000  # python 2
python -m http.server 8000 # python 3

And on the other side just use wget to download it

wget http://[ip address]:8000/[some big file]

Any network activity could be limited by the server admin and the usual indicator is that your speed is maintained at a nice stable level (e.g. 500KB/s)

╰ゝ天使的微笑 2024-12-04 05:27:23

iperf 可用于网络性能测试,可在所有优秀的存储库中找到,并且有大量有关使用技巧的文章。

http://iperf.sourceforge.net/

随机使用文章:

http://www.nanog.org/meetings/nanog43/presentations/Dugan_Iperf_N43.pdf

http://maddhat.com/testing-network-performance-using-iperf-3

使用 scp 等文件传输程序或 ftp 引入磁盘 IO 作为瓶颈源。

iperf is there for network performance testing, available in all good repositories, and plenty of articles for usage tips.

http://iperf.sourceforge.net/

Random usage articles:

http://www.nanog.org/meetings/nanog43/presentations/Dugan_Iperf_N43.pdf

http://maddhat.com/testing-network-performance-using-iperf-3

Using file transfer programs like scp or ftp brings in disk IO as a bottleneck source.

风情万种。 2024-12-04 05:27:23

我预计会减慢多少?加密不应该有太多开销。此外,此速度测试的目的是测量服务器到服务器的 I/O 性能,因此您是否不希望它反映典型的通信类型(即加密)?

服务器管理员也可以限制 scp 带宽使用吗?我如何知道它是否受到限制?是的,这在网络的各个层都是可能的。例如,使用 tc (示例 此处),以及在路由器级别。如果您拥有 sudo 权限,您可以检查 tc 限制是否到位。否则,您可以尝试使用不同的机器,没有限制,看看速度是否不同。如果它是在路由器级别完成的,您就没有简单的方法可以知道。

这是一个 bash 脚本,它将 1) 检查服务器是否可访问,2) 创建给定大小的文件,3) 使用 scp 测量上传和可选的下载速率,4)本地和远程删除文件。

speed_test.sh --server=1.2.3.4 --test_size=128 --do_download=1 --server_dir=. 使用它

信用说明:这是我对最初发布的脚本的修改 这里

#!/bin/bash

test_file=".scp-test-file"

# usage function
function usage()
{
   cat << HEREDOC
   Usage: $progname --server=<ip address> [--test_size=<MB> --do_download=<0/1> --server_dir=<server side dir>]
   optional arguments:
     -h, --help           show this help message and exit
HEREDOC
}

# initialize variables and defaults
progname=$(basename $0)
server=
server_dir=./
do_download=1
test_size=10

###
# all args
L=(server \
do_download \
test_size \
server_dir)

arg_parse_str="help"
for arg in "${L[@]}"; do
    arg_parse_str=${arg_parse_str},${arg}:
done
#echo $arg_parse_str

OPTS=$(getopt -o "h" --long ${arg_parse_str} -n "$progname" -- "$@")
if [ $? != 0 ] ; then echo "Error in command line arguments." >&2 ; usage; exit 1 ; fi
eval set -- "$OPTS"

while true; do
  # uncomment the next line to see how shift is working
  # echo "\$1:\"$1\" \$2:\"$2\""
  case "$1" in
    -h | --help ) usage; exit; ;;
    -- ) shift; break ;;
  esac
  found=
  for arg in "${L[@]}"; do
    if [ "$1" == "--$arg" ]; then
        declare ${arg}="$2";
        shift 2;
        found=1
        break
    fi
  done
  if [ -z "$found" ]; then
    break
  fi
done

if [ -z "$server" ]
then
    usage;
    exit;
fi

#[[ -z $(nc -W 1 -w 10 $server 22 2>/dev/null) ]] && echo "$server unreachable" && exit 0
#if your nc complains about not having -i command line option then use the line above
[[ -z $(nc -i 1 -w 10 $server 22 2>/dev/null) ]] && echo "$server unreachable" && exit 0


# generate a file of all zeros
echo "Generating $test_size MB test file..."
dd if=/dev/zero of=$test_file bs=$(echo "$test_size*1024*1024" | bc) \
  count=1 &> /dev/null
# upload test

echo "Testing upload to $server..."
up_speed=$(scp -v -o 'Compression no' -o 'StrictHostKeyChecking no' $test_file $server:$server_dir/$test_file 2>&1 | \
  grep "Bytes per second" | \
  sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\1/g")
up_speed=$(echo "($up_speed/1000)" | bc)
echo "Upload speed:   $up_speed KBps on $server"

if [ "$do_download" == "1" ]; then
    # download test
    echo "Testing download from $server..."
    down_speed=$(scp -v -o 'Compression no' -o 'StrictHostKeyChecking no' $server:$server_dir/$test_file $test_file 2>&1 | \
      grep "Bytes per second" | \
      sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\2/g")
    down_speed=$(echo "($down_speed/1000)" | bc)
    echo "Download speed: $down_speed KBps on $server"
fi

# clean up
echo "Removing test file, $server:$server_dir/$test_file..."
ssh $server "rm $server_dir/$test_file"
echo "Removing test file locally..."
rm $test_file

How much slowdown should I be expecting? Encryption should not be much overhead. Also, the purpose of this speed test is to measure sever to server I/O performance, so wouldn't you want that to reflect the typical type of communication, which would be with encryption?

Also can the scp bandwidth usage be capped by the server admin? How do I know if it is capped? Yes, this is possible at various tiers in the network. For example, using tc (example here), and at the router level. If you have sudo privileges you can check if tc limits are in place. Otherwise, you could try using a different machine without limits and see if the speed is different. If it's done at the router level you have no easy way of knowing.

Here's a bash script that will 1) check if a server is reachable, 2) create a file of a given size, 3) use scp to measure upload and optionally download rates, 4) delete the file locally and remotely.

Use it like speed_test.sh --server=1.2.3.4 --test_size=128 --do_download=1 --server_dir=.

Credit note: It is my modification of the script originally posted here.

#!/bin/bash

test_file=".scp-test-file"

# usage function
function usage()
{
   cat << HEREDOC
   Usage: $progname --server=<ip address> [--test_size=<MB> --do_download=<0/1> --server_dir=<server side dir>]
   optional arguments:
     -h, --help           show this help message and exit
HEREDOC
}

# initialize variables and defaults
progname=$(basename $0)
server=
server_dir=./
do_download=1
test_size=10

###
# all args
L=(server \
do_download \
test_size \
server_dir)

arg_parse_str="help"
for arg in "${L[@]}"; do
    arg_parse_str=${arg_parse_str},${arg}:
done
#echo $arg_parse_str

OPTS=$(getopt -o "h" --long ${arg_parse_str} -n "$progname" -- "$@")
if [ $? != 0 ] ; then echo "Error in command line arguments." >&2 ; usage; exit 1 ; fi
eval set -- "$OPTS"

while true; do
  # uncomment the next line to see how shift is working
  # echo "\$1:\"$1\" \$2:\"$2\""
  case "$1" in
    -h | --help ) usage; exit; ;;
    -- ) shift; break ;;
  esac
  found=
  for arg in "${L[@]}"; do
    if [ "$1" == "--$arg" ]; then
        declare ${arg}="$2";
        shift 2;
        found=1
        break
    fi
  done
  if [ -z "$found" ]; then
    break
  fi
done

if [ -z "$server" ]
then
    usage;
    exit;
fi

#[[ -z $(nc -W 1 -w 10 $server 22 2>/dev/null) ]] && echo "$server unreachable" && exit 0
#if your nc complains about not having -i command line option then use the line above
[[ -z $(nc -i 1 -w 10 $server 22 2>/dev/null) ]] && echo "$server unreachable" && exit 0


# generate a file of all zeros
echo "Generating $test_size MB test file..."
dd if=/dev/zero of=$test_file bs=$(echo "$test_size*1024*1024" | bc) \
  count=1 &> /dev/null
# upload test

echo "Testing upload to $server..."
up_speed=$(scp -v -o 'Compression no' -o 'StrictHostKeyChecking no' $test_file $server:$server_dir/$test_file 2>&1 | \
  grep "Bytes per second" | \
  sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\1/g")
up_speed=$(echo "($up_speed/1000)" | bc)
echo "Upload speed:   $up_speed KBps on $server"

if [ "$do_download" == "1" ]; then
    # download test
    echo "Testing download from $server..."
    down_speed=$(scp -v -o 'Compression no' -o 'StrictHostKeyChecking no' $server:$server_dir/$test_file $test_file 2>&1 | \
      grep "Bytes per second" | \
      sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\2/g")
    down_speed=$(echo "($down_speed/1000)" | bc)
    echo "Download speed: $down_speed KBps on $server"
fi

# clean up
echo "Removing test file, $server:$server_dir/$test_file..."
ssh $server "rm $server_dir/$test_file"
echo "Removing test file locally..."
rm $test_file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文