Measure network performance using iperf3


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)
  • Concept of NIC device, switch and subnet
  • Basic usage of ip command


iperf3 command

What is iperf3?

iperf3 -s [ options ]
iperf3 -c server [ options ]
  • iperf3 : Measure network performance of two computers.
  • There are also iperf2 and iperf.


Installation

  • CentOS
sudo yum install iperf3 -y
  • Ubuntu
sudo apt-get install iperf3 -y


Usage

  • In two computers, decide one is server and the other is client. After decide each of it, run each command like below.
  • Port should be opened in each computer.
  • iperf3 use 5201 port.

Server

  • Use below command
iperf3 -s

Client

  • Use below command
  • Put IP address of server to IP ADDRESS which you want to measure performance. Put above iperf3 running server’s IP.
iperf3 -c [IP ADDRESS]


Example

Computer network information

  • Server
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:3e:6c:4f:da:2b brd ff:ff:ff:ff:ff:ff
    inet 10.136.105.252/16 brd 10.136.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::503e:6cff:fe4f:da2b/64 scope link
       valid_lft forever preferred_lft forever
  • Client
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 9e:79:07:2a:26:e3 brd ff:ff:ff:ff:ff:ff
    inet 10.136.107.214/16 brd 10.136.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::9c79:7ff:fe2a:26e3/64 scope link
       valid_lft forever preferred_lft forever

Run in server

# Update package list
$ sudo apt-get update -y

# Install package
$ sudo apt-get install iperf3 -y

# Run iperf3 server
$ iperf3 -s

Run in client

# Update package list
$ sudo apt-get update -y

# Install package
$ sudo apt-get install iperf3 -y

# Run iperf3 server
$ iperf3 -c 10.136.105.252

Result

  • Server
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.136.107.214, port 36216
[  5] local 10.136.105.252 port 5201 connected to 10.136.107.214 port 36218
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   251 MBytes  2.11 Gbits/sec
[  5]   1.00-2.00   sec   238 MBytes  1.99 Gbits/sec
[  5]   2.00-3.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   3.00-4.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   4.00-5.00   sec   241 MBytes  2.02 Gbits/sec
[  5]   5.00-6.00   sec   237 MBytes  1.99 Gbits/sec
[  5]   6.00-7.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   7.00-8.00   sec   242 MBytes  2.03 Gbits/sec
[  5]   8.00-9.00   sec   238 MBytes  2.00 Gbits/sec
[  5]   9.00-10.00  sec   237 MBytes  1.99 Gbits/sec
[  5]  10.00-10.04  sec  10.2 MBytes  2.07 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.04  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-10.04  sec  2.35 GBytes  2.01 Gbits/sec                  receiver
  • Client
Connecting to host 10.136.105.252, port 5201
[  4] local 10.136.107.214 port 36218 connected to 10.136.105.252 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   262 MBytes  2.20 Gbits/sec  16168   97.6 KBytes
[  4]   1.00-2.00   sec   239 MBytes  2.00 Gbits/sec  16140    451 KBytes
[  4]   2.00-3.00   sec   240 MBytes  2.01 Gbits/sec  13883    136 KBytes
[  4]   3.00-4.00   sec   238 MBytes  2.00 Gbits/sec  11752    365 KBytes
[  4]   4.00-5.00   sec   238 MBytes  2.00 Gbits/sec  18333    297 KBytes
[  4]   5.00-6.00   sec   238 MBytes  1.99 Gbits/sec  19573    122 KBytes
[  4]   6.00-7.00   sec   238 MBytes  1.99 Gbits/sec  18483    115 KBytes
[  4]   7.00-8.00   sec   234 MBytes  1.96 Gbits/sec  17792    229 KBytes
[  4]   8.00-9.00   sec   241 MBytes  2.02 Gbits/sec  15119   1.20 MBytes
[  4]   9.00-10.00  sec   239 MBytes  2.00 Gbits/sec  23006   93.3 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  2.35 GBytes  2.02 Gbits/sec  170249             sender
[  4]   0.00-10.00  sec  2.35 GBytes  2.01 Gbits/sec                  receiver

iperf Done.


Reference

grep과 옵션을 이용해 현재 및 하위 폴더 파일들에서 문자열 혹은 내용을 찾아보자.


환경

  • Linux 기반 시스템
  • Bash shell(/bin/bash)


grep 명령어

grep 명령어란?

grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
  • grep : 어떤 주어진 패턴에 맞는 문자열을 출력해주는 명령어입니다. 다양한 옵션과 방법으로 많이 사용합니다.


r과 n옵션으로 하위 파일들 내용 모두 검색하기

사용법

  • 찾고자하는 폴더 또는 경로에서 아래 명령어를 사용
grep -rn [PATTERN]

기본 예제

  • -r : 하위 폴더에 있는 파일까지 모두 검색해주는 옵션
  • -n : 해당 패턴이 일치하는 줄도 같이 출력해주는 옵션
$ grep -rn "abc def hij"
test/test_ascii.txt:2:abc def hij

여러 패턴 찾기

  • -e : 여러 패턴을 찾을 수 있게 해주는 옵션 => OR
$ grep -rn -e "send" -e "test"
.gitignore:41:# Unit test / coverage reports
.gitignore:47:nosetests.xml
.gitignore:51:.pytest_cache/
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
...

특정 패턴 제외하기

  • -v : 특정 패턴을 제외해주는 옵션
$ grep -rn -e "send" -e "test" | grep -v ".gitignore"
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
reminder.py:6:def sendMail(sender_email, receiver_email, app_password ,msg):
reminder.py:9:    smtp.login(sender_email, app_password)
...

특정 폴더들 지정하기

  • 다음처럼 특정 패턴들과 함께 폴더들을 지정할 수 있습니다.
$ grep -rn -e "def sednMail" -e "with open" MailReminder ./test/neutron
MailReminder/reminder.py:19:with open('/home/twpower/MailReminder/account.json') as account_json_file:
./test/neutron/doc/source/contributor/internals/quality_of_service.rst:349:combination with openflow rules.
...


참고자료

Find contents or string in current or subfolder files using grep and its option


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)


grep command

What is grep?

grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
  • grep : Print lines matching a pattern. It can be used with other commands and various options.


Find contents in all subfolder files using r and n option

Usage

  • Use below command in folder or directory where you want to find
grep -rn [PATTERN]

Basic example

  • -r : Find all subdirectory files recursively
  • -n : Print matching string with line number
$ grep -rn "abc def hij"
test/test_ascii.txt:2:abc def hij

Find many of patterns

  • -e : You can find more than one pattern => OR
$ grep -rn -e "send" -e "test"
.gitignore:41:# Unit test / coverage reports
.gitignore:47:nosetests.xml
.gitignore:51:.pytest_cache/
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
...

Exclude specific pattern

  • -v : Exclude specific pattern
$ grep -rn -e "send" -e "test" | grep -v ".gitignore"
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
reminder.py:6:def sendMail(sender_email, receiver_email, app_password ,msg):
reminder.py:9:    smtp.login(sender_email, app_password)
...

Give specific directory

  • You can give specific directories as arguments.
$ grep -rn -e "def sednMail" -e "with open" MailReminder ./test/neutron
MailReminder/reminder.py:19:with open('/home/twpower/MailReminder/account.json') as account_json_file:
./test/neutron/doc/source/contributor/internals/quality_of_service.rst:349:combination with openflow rules.
...


Reference

patch 파일을 만들고 적용해보자.


환경

  • Linux 기반 시스템
  • Bash shell(/bin/bash)
  • patch, diff 그리고 git 명령어


patch, diff 그리고 git 명령어

patch 명령어

patch -pNUM < patchfile
  • patch : 패치파일을 이용해 프로젝트나 파일에 패치를 적용하는 명령어입니다.
  • 패치파일은 diffgit diff를 이용해 만들 수 있습니다.


diff 명령어

diff [OPTION]... FILES
  • diff : 두 파일 또는 프로젝트의 diff를 줄별로 비교 및 분석해주는 명령어입니다.
  • 자세한 예제는 아래 나와있습니다.


git diff 명령어

git diff
  • git diff : 현재 git이 있는 프로젝트에서 어떤 파일들이 바뀌었는지를 나타내는 명령어입니다.
  • git diff를 이용해 바로 patch 파일을 만들 수 있습니다.


diff를 이용해 patch 파일 만들기

두 파일간에 patch 파일 만들기

사용법

diff -urN [old file] [patched file]

예시

# Make diff
diff -urN test-old.txt test-new.txt

# Make patch file
diff -urN test-old.txt test-new.txt > patch.patch


프로젝트 폴더간 patch 파일 만들기

사용법

diff -urN [old directory] [patched directory]

예시

# Make diff
diff -urN neutron neutron_patched

# Make diff file
diff -urN neutron neutron_patched > neutron_patch.patch


git diff로 patch 파일 만들기

  • 바로 명령어를 사용해 파일로 남겨주시면 됩니다.
git diff > [patch file name]


patch 파일을 적용하기

사용법

patch -pNUM < patchfile
  • 패치를 할 프로젝트나 파일의 위치에서 위의 명령어를 사용해 적용합니다.
  • NUM은 패치 파일에 나와있는 경로에서 몇개를 제외할지를 나타냅니다. 예를 들어서 패치파일에 a/neutron/service.py로 나와있고 -p1을 하게 되면 앞에서 하나의 경로를 제외한 neutron/service.py에 적용이 되게 되며 만약 -p2를 하게 된다면 service.py에 적용이 되게 됩니다.


예시

  • neutron 프로젝트 안에서 패치 적용
  • neutron_patch.patch 파일이 neutron 프로젝트 폴더 바로 바깥에 미리 생성되어 있어야 합니다.
# In neutron project
cd neutron

# Apply patch file
# Option -p1 could be different depends on your patch file
patch -p1 < ../neutron_patch.patch


사용 예제

0. 과정

  • neutron 프로젝트를 clone하고 파일을 조금 변경한 후에 git diff를 이용해 patch 파일을 생성합니다.
  • neutron 프로젝트를 다시 원상태로 복구하고 patch 파일을 적용해서 파일이 바뀌는지 확인합니다.

1. neutron 프로젝트 클론 및 수정

git clone https://github.com/openstack/neutron.git
cd neutron

vi [any file in this project directory]

1. 사용할 patch 파일 생성

  • patch 파일은 자유롭게 만드셔도 됩니다.
git diff > ../neutron_patch.patch

neutron_patch.patch

diff --git a/neutron/service.py b/neutron/service.py
index 06bf4cd..67f93fe 100644
--- a/neutron/service.py
+++ b/neutron/service.py
@@ -1,4 +1,4 @@
-# Copyright 2011 VMware, Inc
+#aidfjaldfja;ifdjsaoe# Copyright 2011 VMware, Inc
 # All Rights Reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/neutron/worker.py b/neutron/worker.py
index 81e7110..a330fe0 100644
--- a/neutron/worker.py
+++ b/neutron/worker.py
@@ -9,7 +9,7 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
-
+#akdfjakl;dfja;kfld
 from neutron_lib import worker
 from oslo_config import cfg
 from oslo_service import loopingcall

2. patch 파일 적용

  • neutron을 원상태로 복구하고 아래 명령어를 시행합니다.
patch -p1 < ../neutron_patch.patch


참고자료

Make patch file and apply it.


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)
  • patch, diff and git command


patch, diff and git command

patch command

patch -pNUM < patchfile
  • patch : Apply a patch file to an project or file.
  • Patch file can be made by using diff or git diff.


diff command

diff [OPTION]... FILES
  • diff : Compare files or projects line by line
  • Detail example is in below.


git diff command

git diff
  • git diff : Show current git project’s diff status.
  • You can make patch file using git diff command.


Make patch file using diff

Make patch file between two files

Usage

diff -urN [old file] [patched file]

Example

# Make diff
diff -urN test-old.txt test-new.txt

# Make patch file
diff -urN test-old.txt test-new.txt > patch.patch


Make patch file between two project directories

Usage

diff -urN [old directory] [patched directory]

Example

# Make diff
diff -urN neutron neutron_patched

# Make diff file
diff -urN neutron neutron_patched > neutron_patch.patch


Make patch file using git diff

  • Directly use git command
git diff > [patch file name]


Apply patch file

Usage

patch -pNUM < patchfile
  • In project or file directory that you want to apply patch, use above command.
  • NUM means that how many root directories you are going to remove in patch file. For example, in patch file there is file patch like a/neutron/service.py. If we use -p1 option, then patch will be applied file path neutron/service.py. If we use -p2 option, then patch will be applied to file path service.py.


Example

  • Apply patch in neutron project directory
  • neutron_patch.patch file must exist just out of neutron project
# In neutron project
cd neutron

# Apply patch file
# Option -p1 could be different depends on your patch file
patch -p1 < ../neutron_patch.patch


Usage Example

0. Process

  • Clone neutron project and edit it for making patch file. Make patch file from git diff.
  • Revert all diffs in neutron project and apply patch file. Check patch is applied.

1. Clone neutron project and modify it

git clone https://github.com/openstack/neutron.git
cd neutron

vi [any file in this project directory]

2. Make patch file

  • Make patch file freely.
git diff > ../neutron_patch.patch

neutron_patch.patch

diff --git a/neutron/service.py b/neutron/service.py
index 06bf4cd..67f93fe 100644
--- a/neutron/service.py
+++ b/neutron/service.py
@@ -1,4 +1,4 @@
-# Copyright 2011 VMware, Inc
+#aidfjaldfja;ifdjsaoe# Copyright 2011 VMware, Inc
 # All Rights Reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/neutron/worker.py b/neutron/worker.py
index 81e7110..a330fe0 100644
--- a/neutron/worker.py
+++ b/neutron/worker.py
@@ -9,7 +9,7 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
-
+#akdfjakl;dfja;kfld
 from neutron_lib import worker
 from oslo_config import cfg
 from oslo_service import loopingcall

2. Apply patch file

  • Revert all diffs and run below command to apply patch file
patch -p1 < ../neutron_patch.patch


Reference