Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: support for generating flame graph #6136

Merged
merged 74 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
bdf4823
ci: add perf test and generate flame graph
tzssangglass Jan 16, 2022
2d842f8
add trigger
tzssangglass Jan 16, 2022
3a62b87
add perf.sh
tzssangglass Jan 16, 2022
4bdae40
update install deps order
tzssangglass Jan 16, 2022
ffba68b
update
tzssangglass Jan 16, 2022
1244a38
add debug
tzssangglass Jan 16, 2022
b9b32bc
add debug
tzssangglass Jan 16, 2022
325f55a
rm debug
tzssangglass Jan 16, 2022
f40bbfb
Merge branch 'master' into flamegraph
tzssangglass Jan 16, 2022
422370a
fix typo
tzssangglass Jan 16, 2022
a29ece5
add test
tzssangglass Jan 17, 2022
aec24c4
add install_stap_tools
tzssangglass Jan 17, 2022
6070279
fix typo
tzssangglass Jan 17, 2022
d3cd626
remove bionic-security repo
tzssangglass Jan 17, 2022
24d9d1c
test
tzssangglass Jan 17, 2022
58d9eb5
rm debug
tzssangglass Jan 17, 2022
ef17fc7
chore order of cmd
tzssangglass Jan 17, 2022
aba8099
add debug
tzssangglass Jan 17, 2022
5769b3b
build apisix-base
tzssangglass Jan 17, 2022
4970bad
build apisix-base
tzssangglass Jan 17, 2022
4445693
build apisix-base
tzssangglass Jan 17, 2022
45699e5
build apisix-base
tzssangglass Jan 17, 2022
d03b9be
chore
tzssangglass Jan 17, 2022
d6c5000
chore
tzssangglass Jan 17, 2022
a434fc6
chore
tzssangglass Jan 17, 2022
b821024
basic completed
tzssangglass Jan 17, 2022
80f6b15
rm debug
tzssangglass Jan 17, 2022
a604c01
chore
tzssangglass Jan 17, 2022
45222c0
chore-2
tzssangglass Jan 17, 2022
25d1a44
chore-3
tzssangglass Jan 17, 2022
7693713
add debug
tzssangglass Jan 17, 2022
af50825
chore-4
tzssangglass Jan 17, 2022
8e4770a
fix
tzssangglass Jan 17, 2022
ec26792
fix-2
tzssangglass Jan 17, 2022
d79458d
debug
tzssangglass Jan 17, 2022
f18af90
chore-5
tzssangglass Jan 17, 2022
53a0e6d
rm debug
tzssangglass Jan 17, 2022
7eae29b
fix-3
tzssangglass Jan 17, 2022
24be7ac
fix-4
tzssangglass Jan 17, 2022
1ad47b1
fix-5
tzssangglass Jan 17, 2022
355c360
fix-6
tzssangglass Jan 17, 2022
d5e0e1c
fix-7
tzssangglass Jan 17, 2022
f84ea26
complete
tzssangglass Jan 17, 2022
a8d22f3
for test
tzssangglass Jan 17, 2022
27aac2f
for test on apisix
tzssangglass Jan 17, 2022
23a941f
add ldap
tzssangglass Jan 18, 2022
7b0734b
adjust name
tzssangglass Jan 19, 2022
4c6fa29
chore repo
tzssangglass Jan 19, 2022
3c772f5
Merge branch 'master' of https://github.com/apache/apisix into flameg…
tzssangglass Jan 20, 2022
16fcddb
adjust the trigger conditions and result display
tzssangglass Jan 20, 2022
5639bc4
adjust the trigger conditions
tzssangglass Jan 20, 2022
5d581ba
adjust the trigger conditions
tzssangglass Jan 20, 2022
aa406bf
echo test
tzssangglass Jan 20, 2022
708223f
echo test
tzssangglass Jan 20, 2022
91f62d0
echo test
tzssangglass Jan 20, 2022
b89c84d
echo test
tzssangglass Jan 20, 2022
8b4ebf0
try with add action as submodule
tzssangglass Jan 20, 2022
09c0de8
fix yaml format
tzssangglass Jan 20, 2022
c71c418
add test duration
tzssangglass Jan 20, 2022
e5f572e
rm local action
tzssangglass Jan 20, 2022
1e5cb4c
rm echo test
tzssangglass Jan 20, 2022
1ec68c7
add workflow for writing comments permissions in CI
tzssangglass Feb 8, 2022
a168e8f
fix typo
tzssangglass Feb 8, 2022
ef2ba3c
Merge branch 'master' of https://github.com/apache/apisix into flameg…
tzssangglass Feb 8, 2022
8db8508
add comments
tzssangglass Feb 9, 2022
8c03fd8
test for create comments
tzssangglass Feb 9, 2022
cd9d162
debug
tzssangglass Feb 9, 2022
b5c69de
fix CI error
tzssangglass Feb 9, 2022
85947b3
rm echo
tzssangglass Feb 9, 2022
703a6e9
rm unused code
tzssangglass Feb 10, 2022
1ae6b6c
rm action
tzssangglass Feb 10, 2022
f876d1f
add comments
tzssangglass Feb 15, 2022
900dd69
fix typo
tzssangglass Feb 15, 2022
9f7901b
Merge branch 'master' of https://github.com/apache/apisix into flameg…
tzssangglass Feb 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ jobs:

- name: Linux Install
run: |
sudo --preserve-env=OPENRESTY_VERSION \
./ci/${{ matrix.os_name }}_runner.sh do_install
sudo --preserve-env=OPENRESTY_VERSION \
./ci/${{ matrix.os_name }}_runner.sh do_install

- name: Linux Script
run: sudo ./ci/${{ matrix.os_name }}_runner.sh script
56 changes: 56 additions & 0 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Performance Test

on:
pull_request:
branches: [master, 'release/**']
paths-ignore:
- 'docs/**'
- '**/*.md'

jobs:
performance:
if: github.event_name == 'pull_request' || github.event.label.name == 'performance'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only rely on the label? The pull request can be triggered by any user.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. However, the current test case only contains jwt-auth, and I feel that it seems too early to combine the user's PR with the test case. It would be nice to have targeted tests for the user's PR. Do you have any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can apply a label if needed. Note that people can run anything based on their PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can apply a label if needed

Now this PR is satisfied, add performance and it will run. To run it again you need to remove performance and add it again.

Note that people can run anything based on their PR.

Yes, the idealization is so. But this requires continued enhancements to the performance testing framework.
Maybe we can change it the next time we need to run performance tests for other PRs.

runs-on: ubuntu-18.04
timeout-minutes: 45

steps:
- name: Check out code
uses: actions/[email protected]
with:
submodules: recursive

- name: Cache deps
uses: actions/[email protected]
env:
cache-name: cache-deps
with:
path: deps
key: ${{ runner.os }}-${{ env.cache-name }}-${{ matrix.os_name }}-${{ hashFiles('rockspec/apisix-master-0.rockspec') }}

- name: Install Dependencies
run: sudo ./ci/performance_test.sh install_dependencies

- name: Install wrk2
run: sudo ./ci/performance_test.sh install_wrk2

- name: Install SystemTap Tools
run: sudo ./ci/performance_test.sh install_stap_tools

- name: Perf Test
run: ./ci/performance_test.sh run_performance_test

- name: Upload Performance Test Result
uses: actions/upload-artifact@v2
with:
name: perf.txt
path: |
output/performance.txt
retention-days: 3

- name: Upload flamegrpah
uses: actions/upload-artifact@v2
with:
name: flamegraph.svg
path: |
output/flamegraph.svg
retention-days: 3
117 changes: 117 additions & 0 deletions ci/performance_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

. ./ci/common.sh

set -ex

install_dependencies() {
apt-get -y update --fix-missing
apt-get -y install lua5.1 liblua5.1-0-dev libldap2-dev
export_or_prefix
export OPENRESTY_VERSION=source
./utils/linux-install-openresty.sh
bash utils/install-dependencies.sh install_luarocks
make deps
}

install_wrk2() {
cd ..
git clone https://github.com/giltene/wrk2
cd wrk2 || true
make
ln -s $PWD/wrk /usr/bin
cd ..
}

install_stap_tools() {
# install ddeb source repo
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C8CAB6595FDFF622

codename=$(lsb_release -c | awk '{print $2}')
sudo tee /etc/apt/sources.list.d/ddebs.list << EOF
deb http://ddebs.ubuntu.com/ ${codename} main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-proposed main restricted universe multiverse
EOF

sudo apt-get update
sudo apt-get install linux-image-$(uname -r)-dbgsym
sudo apt install elfutils libdw-dev
sudo apt-get install -y python3-setuptools python3-wheel

# install systemtap
cd /usr/local/
wget http://sourceware.org/systemtap/ftp/releases/systemtap-4.6.tar.gz
tar -zxf systemtap-4.6.tar.gz
mv systemtap-4.6 systemtap
cd systemtap
./configure && make all && sudo make install && stap --version
cd ..

# see https://github.com/openresty/stapxx/pull/48
git clone https://github.com/api7/stapxx.git -b luajit-gc64
git clone https://github.com/openresty/openresty-systemtap-toolkit.git
git clone https://github.com/brendangregg/FlameGraph.git
}


run_performance_test() {
sudo chmod -R 777 ./
ulimit -n 10240

pip3 install -r t/perf/requirements.txt --user

#openresty-debug
export OPENRESTY_PREFIX="/usr/local/openresty-debug"
export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/bin:$OPENRESTY_PREFIX/luajit/bin:$PATH

mkdir output
python3 ./t/perf/test_http.py >$PWD/output/performance.txt 2>&1 &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this script end up automatically?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, duration is 100s


sleep 1

# stapxx
export STAP_PLUS_HOME=/usr/local/stapxx
export PATH=/usr/local/stapxx:/usr/local/stapxx/samples:$PATH
# openresty-systemtap-toolkit
export PATH=/usr/local/openresty-systemtap-toolkit:$PATH
# FlameGraph
export PATH=/usr/local/FlameGraph:$PATH

sudo env PATH=$PATH /usr/local/stapxx/samples/lj-lua-stacks.sxx --arg time=30 --skip-badvars -x $(pgrep -P $(cat logs/nginx.pid) -n -f worker) > /tmp/tmp.bt
sudo env PATH=$PATH /usr/local/openresty-systemtap-toolkit/fix-lua-bt /tmp/tmp.bt > /tmp/flame.bt
sudo env PATH=$PATH /usr/local/FlameGraph/stackcollapse-stap.pl /tmp/flame.bt > /tmp/flame.cbt
sudo env PATH=$PATH /usr/local/FlameGraph/flamegraph.pl /tmp/flame.cbt > $PWD/output/flamegraph.svg
}

case_opt=$1
case $case_opt in
(install_dependencies)
install_dependencies
;;
(install_wrk2)
install_wrk2
;;
(install_stap_tools)
install_stap_tools
;;
(run_performance_test)
run_performance_test
;;
esac
14 changes: 12 additions & 2 deletions t/perf/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def create_conf():
"type": "roundrobin"
}]

# expose public api
routes.append({
"uri": "/gen_token",
"plugins": {
"public-api": {
"uri": "/apisix/plugin/jwt/sign"
}
},
})

conf = {}
conf["routes"] = routes
conf["consumers"] = consumers
Expand Down Expand Up @@ -128,7 +138,7 @@ def create_env():
class TestHTTP(unittest.TestCase):

def setUp(self):
self.duration = os.environ.get("APISIX_PERF_DURATION", "30")
self.duration = os.environ.get("APISIX_PERF_DURATION", "300")
self.n_client = os.environ.get("APISIX_PERF_CLIENT", "100")
self.n_thread = os.environ.get("APISIX_PERF_THREAD", "2")
self.qps = os.environ.get("APISIX_PERF_QPS", "8000")
Expand All @@ -143,7 +153,7 @@ def test_perf(self):
conn = http.client.HTTPConnection("127.0.0.1", port=9080)
for i in range(RULE_SIZE):
i = str(i)
conn.request("GET", "/apisix/plugin/jwt/sign?key=user-key-" + i)
conn.request("GET", "/gen_token?key=user-key-" + i)
response = conn.getresponse()
if response.status >= 300:
print("failed to sign, got: %s" % response.read())
Expand Down