Skip to content

Commit ea11966

Browse files
sftp benchmark github action
1 parent ac5bf2f commit ea11966

File tree

3 files changed

+103
-38
lines changed

3 files changed

+103
-38
lines changed

.github/workflows/sftp-benchmark.yml

Lines changed: 87 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
pull_request:
77
branches: [ '*' ]
88

9+
# give permissions to write a comment on the pull request
10+
permissions:
11+
pull-requests: write
12+
actions: read
13+
contents: read
14+
915
concurrency:
1016
group: ${{ github.workflow }}-${{ github.ref }}
1117
cancel-in-progress: true
@@ -43,13 +49,12 @@ jobs:
4349
build_wolfssh:
4450
needs:
4551
- build_wolfssl
46-
- create_matrix
4752
strategy:
4853
fail-fast: false
4954
matrix:
5055
os: [ ubuntu-latest ]
51-
wolfssl: ${{ fromJson(needs.create_matrix.outputs['versions']) }}
52-
name: Build and test wolfsshd
56+
wolfssl: [ master ]
57+
name: Collect SFTP performance
5358
runs-on: ${{ matrix.os }}
5459
timeout-minutes: 10
5560
steps:
@@ -71,53 +76,109 @@ jobs:
7176
- name: configure
7277
working-directory: ./wolfssh/
7378
run : |
74-
./configure --enable-all LDFLAGS="-L${{ github.workspace }}/build-dir/lib" CPPFLAGS="-I${{ github.workspace }}/build-dir/include -DWOLFSSH_NO_FPKI -DWOLFSSH_NO_SFTP_TIMEOUT -DWOLFSSH_MAX_SFTP_RW=4000000 -DMAX_PATH_SZ=120"
79+
./configure --enable-all LDFLAGS="-L${{ github.workspace }}/build-dir/lib" CPPFLAGS="-I${{ github.workspace }}/build-dir/include -DWOLFSSH_NO_FPKI -DWOLFSSH_NO_SFTP_TIMEOUT -DWOLFSSH_MAX_SFTP_RW=4000000 -DMAX_PATH_SZ=120 -DEXAMPLE_SFTP_BENCHMARK"
7580
7681
- name: make
7782
working-directory: ./wolfssh/
7883
run: make
7984

8085
- name: Get Saved OpenSSH Upload Results
81-
uses: actions/downlad-artifact@v4
86+
id: cache-upload
87+
uses: actions/cache@v4
8288
with:
83-
path: ./wolfssh/
84-
artifact_id: 'openssh-upload'
89+
path: wolfssh/openssh-average-download.csv
90+
key: openssh-average-download.csv
91+
fail-on-cache-miss: false
8592

93+
- name: Get Saved OpenSSH Download Results
94+
id: cache-download
95+
uses: actions/cache@v4
96+
with:
97+
path: wolfssh/openssh-average-upload.csv
98+
key: openssh-averavge-upload.csv
99+
fail-on-cache-miss: false
100+
101+
- name: Install gnuplot
102+
run: sudo apt-get install gnuplot
86103

87-
- name: Put test key in authorized keys file
104+
- name: Setup OpenSSH Test Server
105+
working-directory: ./wolfssh/
88106
run: |
89-
touch ~/.ssh/authorized_keys_test
90-
cat ./keys/hansel-*.pub > authorized_keys_test
107+
sudo apt-get install openssh-server
108+
mkdir ~/.ssh
109+
chmod 700 ~/.ssh
110+
echo "AuthorizedKeysFile $PWD/keys/hansel-key-ecc.pub" >> sshd-config-test.txt
111+
echo "PubkeyAuthentication yes" >> sshd-config-test.txt
112+
echo "Subsystem sftp internal-sftp" >> sshd-config-test.txt
113+
echo "KbdInteractiveAuthentication no" >> sshd-config-test.txt
114+
sed -i.bak "s/hansel/$USER/" ./keys/hansel-key-ecc.pub
91115
chmod 600 ./keys/hansel-key-*.pem
92-
sudo systemctl restart sshd
93-
sudo service sshd restart
116+
chmod 600 ./keys/hansel-key-*.pub
117+
sudo mkdir -p /run/sshd
118+
sudo chmod 755 /run/sshd
119+
sudo /usr/sbin/sshd -p 22222 -f sshd-config-test.txt -E $PWD/sshd-log.txt
120+
cat sshd-config-test.txt
121+
ps -e | grep sshd
94122
95123
- name: Run SFTP client benchmark
96124
working-directory: ./wolfssh/
125+
timeout-minutes: 5
97126
run: |
98-
./scripts/get-sftp-benchmark.sh
127+
./scripts/get-sftp-benchmark.sh 22222
99128
100129
- name: Store Upload Speed PNG
101130
uses: actions/upload-artifact@v4
102131
with:
103-
name: upload-results.png
132+
name: upload-results-pr${{ github.event.pull_request.number }}.png
104133
path: wolfssh/upload-results.png
134+
retention-days: 2
105135

106136
- name: Store Download Speed PNG
107137
uses: actions/upload-artifact@v4
108138
with:
109-
name: download-results.png
139+
name: download-results-pr${{ github.event.pull_request.number }}.png
110140
path: wolfssh/download-results.png
141+
retention-days: 2
111142

112-
- name: Comment on PR about performance
113-
env:
114-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143+
- name: Upload OpenSSH Download Results
144+
if: steps.cache-download.outputs.cache-hit != 'true'
145+
uses: actions/cache@v4
146+
with:
147+
path: wolfssh/openssh-average-download.csv
148+
key: openssh-average-download.csv
149+
150+
- name: Upload OpenSSH Upload Results
151+
if: steps.cache-upload.outputs.cache-hit != 'true'
152+
uses: actions/cache@v4
153+
with:
154+
path: wolfssh/openssh-average-upload.csv
155+
key: openssh-average-upload.csv
156+
157+
# Currently the comment in PR does not work correctly
158+
# - name: Comment on PR about performance
159+
# env:
160+
# GITHUB_URL: ${{ github.event.pull_request.comments_url }}
161+
# GH_TOKEN: ${{ github.token }}
162+
# PR_NUMBER: ${{ github.event.pull_request.number }}
163+
# RUN_ID: ${{ github.run_id }}
164+
# run: |
165+
# # Get both artifact IDs
166+
# DOWNLOAD_ARTIFACT=$(gh api repos/${{ github.repository }}/actions/artifacts \
167+
# --jq '.artifacts[] | select(.name | contains("download-results-pr")) | .id')
168+
# UPLOAD_ARTIFACT=$(gh api repos/${{ github.repository }}/actions/artifacts \
169+
# --jq '.artifacts[] | select(.name | contains("upload-results-pr")) | .id')
170+
#
171+
# # Create the comment with direct link to download
172+
# curl -X POST \
173+
# $GITHUB_URL \
174+
# -H "Content-Type: application/json" \
175+
# -H "Authorization: token $GH_TOKEN" \
176+
# -d "{\"body\":\"Performance test results:\n\n- [Download Results](https://github.com/${{ github.repository }}/actions/runs/$RUN_ID/artifacts/$DOWNLOAD_ARTIFACT)\n- [Upload Results](https://github.com/${{ github.repository }}/actions/runs/$RUN_ID/artifacts/$UPLOAD_ARTIFACT)\"}"
177+
178+
- name: Print logs if failed
179+
working-directory: ./wolfssh/
180+
if: failure()
115181
run: |
116-
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
117-
gh pr comment $PR_NUMBER --body "Attached is the performance results" \
118-
--attach download-results.png \
119-
--attach upload-results.png
120-
121-
artifacts:
122-
'openssh-upload': { 'path': 'wolfssh/openssh-average-upload.csv' }
123-
'openssh-download': { 'path': 'wolfssh/openssh-average-download.csv' }
182+
sudo cat sshd-log.txt
183+
cat log.csv
184+

examples/sftpclient/sftpclient.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ static void err_msg(const char* s)
132132
#else
133133
#include <sys/time.h>
134134

135-
double current_time_ms(int);
136-
137135
/* return number of seconds*/
138136
word32 current_time(int reset)
139137
{
@@ -145,6 +143,9 @@ static void err_msg(const char* s)
145143
return (word32)tv.tv_sec;
146144
}
147145

146+
#ifdef EXAMPLE_SFTP_BENCHMARK
147+
double current_time_ms(int);
148+
148149
/* return number of micro seconds */
149150
double current_time_ms(int reset)
150151
{
@@ -155,7 +156,7 @@ static void err_msg(const char* s)
155156
gettimeofday(&tv, 0);
156157
return (word64)(tv.tv_sec*1000000) + tv.tv_usec;
157158
}
158-
159+
#endif
159160
#endif /* USE_WINDOWS_API */
160161
#endif /* !WOLFSSH_NO_TIMESTAMP */
161162

@@ -1107,7 +1108,8 @@ static int doAutopilot(int cmd, char* local, char* remote)
11071108
char fullpath[128] = ".";
11081109
WS_SFTPNAME* name = NULL;
11091110
byte remoteAbsPath = 0;
1110-
#if !defined(WOLFSSH_NO_TIMESTAMP) && !defined(USE_WINDOWS_API)
1111+
#if !defined(WOLFSSH_NO_TIMESTAMP) && !defined(USE_WINDOWS_API) &&\
1112+
defined(EXAMPLE_SFTP_BENCHMARK)
11111113
double currentTime;
11121114
double longBytes = 0;
11131115
FILE* f;
@@ -1144,7 +1146,8 @@ static int doAutopilot(int cmd, char* local, char* remote)
11441146
remote);
11451147
}
11461148

1147-
#if !defined(WOLFSSH_NO_TIMESTAMP) && !defined(USE_WINDOWS_API)
1149+
#if !defined(WOLFSSH_NO_TIMESTAMP) && !defined(USE_WINDOWS_API) &&\
1150+
defined(EXAMPLE_SFTP_BENCHMARK)
11481151
ret = WFOPEN(NULL, &f, fullpath, "rb");
11491152
if (ret != 0 || f == WBADFILE) return WS_BAD_FILE_E;
11501153
if (WFSEEK(NULL, f, 0, WSEEK_END) != 0) {
@@ -1177,7 +1180,8 @@ static int doAutopilot(int cmd, char* local, char* remote)
11771180
fullpath, local);
11781181
}
11791182
}
1180-
#if !defined(WOLFSSH_NO_TIMESTAMP) && !defined(USE_WINDOWS_API)
1183+
#if !defined(WOLFSSH_NO_TIMESTAMP) && !defined(USE_WINDOWS_API) &&\
1184+
defined(EXAMPLE_SFTP_BENCHMARK)
11811185
else {
11821186
currentTime = current_time_ms(0) - currentTime;
11831187
double result;

scripts/get-sftp-benchmark.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
KEY="keys/hansel-key-ecc.pem"
4-
TEST_FILE="/home/jak/Documents/wolfssh-fork/test"
3+
KEY="$PWD/keys/hansel-key-ecc.pem"
4+
TEST_FILE="$PWD/test"
55
FILE_SIZES=("5000" "10000" "50000" "100000" "150000" "200000" "250000" "300000" "350000" "400000" "500000" "1000000")
66
TRANSFER_MBS=""
77
NUMBER_RUNS=10
@@ -19,7 +19,7 @@ fi
1919

2020
do_openssh_put_test() {
2121
cp $TEST_FILE $TEST_FILE-out
22-
sftp_command="sftp -P$PORT -i $KEY jak@127.0.0.1"
22+
sftp_command="sftp -P$PORT -o \"StrictHostKeyChecking no\" -i $KEY $USER@127.0.0.1"
2323
output_file="sftp_log.txt"
2424

2525
# Start the script command to capture the sftp session
@@ -37,7 +37,7 @@ EOF" /dev/null 2>&1 | tee $output_file | while read line; do
3737

3838
do_openssh_get_test() {
3939
cp $TEST_FILE $TEST_FILE-out
40-
sftp_command="sftp -P $PORT -i $KEY jak@127.0.0.1"
40+
sftp_command="sftp -P $PORT -o \"StrictHostKeyChecking no\" -i $KEY $USER@127.0.0.1"
4141
output_file="sftp_log.txt"
4242

4343
# Start the script command to capture the sftp session
@@ -55,14 +55,14 @@ EOF" /dev/null 2>&1 | tee $output_file | while read line; do
5555

5656
do_wolfssh_put_test() {
5757
cp $TEST_FILE $TEST_FILE-out
58-
RESULT=$(./examples/sftpclient/wolfsftp -g -l $TEST_FILE -r $TEST_FILE-out -i $PWD/keys/hansel-key-ecc.der -j $PWD/keys/hansel-key-ecc.pub -u jak -p $PORT)
58+
RESULT=$(./examples/sftpclient/wolfsftp -g -l $TEST_FILE -r $TEST_FILE-out -i $PWD/keys/hansel-key-ecc.der -j $PWD/keys/hansel-key-ecc.pub -u $USER -p $PORT)
5959
TRANSFER_MBS="$(echo "$RESULT" | awk '{print $(NF-0)}' | sed 's/MB\/s//')"
6060
printf " $TRANSFER_MBS" >> $LOG_FILE
6161
}
6262

6363
do_wolfssh_get_test() {
6464
cp $TEST_FILE $TEST_FILE-out
65-
RESULT=$(./examples/sftpclient/wolfsftp -G -l $TEST_FILE-out -r $TEST_FILE -i $PWD/keys/hansel-key-ecc.der -j $PWD/keys/hansel-key-ecc.pub -u jak -p $PORT)
65+
RESULT=$(./examples/sftpclient/wolfsftp -G -l $TEST_FILE-out -r $TEST_FILE -i $PWD/keys/hansel-key-ecc.der -j $PWD/keys/hansel-key-ecc.pub -u $USER -p $PORT)
6666
TRANSFER_MBS="$(echo "$RESULT" | awk '{print $(NF-0)}' | sed 's/MB\/s//')"
6767
printf " $TRANSFER_MBS" >> $LOG_FILE
6868
}

0 commit comments

Comments
 (0)