Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
119 changes: 119 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: "Benchmark"

on:
workflow_dispatch:

permissions:
contents: read

defaults:
run:
shell: bash --noprofile --norc -x -eo pipefail {0}

jobs:
do:
runs-on: ubuntu-latest
name: "Benchmark with latest server version"
steps:
- name: Checkout nats.c
uses: actions/checkout@v4
with: ${{ github.ref }}

- name: "Checkout dependencies (nats.c.deps)"
uses: actions/checkout@v4
with:
repository: nats-io/nats.c.deps
path: deps

# Configure the cmake flags and NATS_... environment variables
- id: cmake-flags
name: Configure cmake flags
env:
flags: -DNATS_BUILD_ARCH=64
-DCMAKE_BUILD_TYPE=Release
-DNATS_BUILD_STREAMING=ON
-DNATS_BUILD_USE_SODIUM=ON
-DNATS_PROTOBUF_DIR=${{ github.workspace}}/deps/pbuf
-DNATS_SODIUM_DIR=${{ github.workspace}}/deps/sodium
run: |
flags="$flags -DNATS_BUILD_WITH_TLS=ON"
flags="$flags -DNATS_BUILD_TLS_FORCE_HOST_VERIFY=ON"
flags="$flags -DNATS_WITH_EXPERIMENTAL=ON"
echo "flags=$flags" >> $GITHUB_OUTPUT

# Install build dependencies
- name: Install gcc
run: |
sudo apt-get -q update
sudo apt-get -y install gcc

# Build
- name: CMake
run: |
mkdir -p build
cd build
cmake .. ${{ steps.cmake-flags.outputs.flags }}
make rebuild_cache && make

- name: "Download nats-server version main"
working-directory: ./build
run: |
for c in 1 2 3 4 5
do
echo "Attempt $c to download binary for main"
rm -f ./nats-server
curl -sf "https://binaries.nats.dev/nats-io/nats-server/v2@$rel" | PREFIX=. sh
# We are sometimes getting nats-server of size 0. Make sure we have a
# working nats-server by making sure we get a version number.
v="$(./nats-server -v)"
if [ "$v" != "" ]; then
break
fi
done
mv ./nats-server ../deps/nats-server/nats-server

- name: "Cache for base benchmark for main"
id: cache-base-bench
uses: actions/cache@v4
with:
key: bench-main
path: ./build/bench-main.log

- name: "Benchmark the branch"
working-directory: ./build
run: |
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'bench' --timeout 600 -VV | tee bench.log

- name: "Checkout nats.c for main"
if: steps.cache-base-bench.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
ref: main
clean: false

- name: "Benchmark main for comparison"
if: steps.cache-base-bench.outputs.cache-hit != 'true'
run: |
mkdir -p build
cd build
rm -rf CMakeFiles CMakeCache.txt
cmake .. ${{ steps.cmake-flags.outputs.flags }}
make rebuild_cache && make
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'bench' --timeout 600 -VV | tee bench-main.log

- name: "Checkout branch"
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
clean: false

- name: "Compare benchmark to main"
run: |
cd build
go run ../test/diffstat_sub_async.go bench-main.log bench.log
54 changes: 1 addition & 53 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
arch:
type: string
default: "64"
benchmark:
type: string
default: "OFF"
compiler:
type: string
default: "gcc"
Expand Down Expand Up @@ -112,7 +109,7 @@ jobs:
flags="$flags -DDEV_MODE=ON"
fi
if [[ "${{ inputs.experimental }}" == "ON" ]]; then
flags="$flags -DNATS_EXPERIMENTAL=ON"
flags="$flags -DNATS_WITH_EXPERIMENTAL=ON"
fi
if [[ -n "${{ inputs.sanitize }}" ]]; then
flags="$flags -DNATS_SANITIZE=ON -DCMAKE_C_FLAGS=-fsanitize=${{ inputs.sanitize }}"
Expand Down Expand Up @@ -181,7 +178,6 @@ jobs:
fi

- name: "Test"
if: inputs.benchmark == 'OFF'
working-directory: ./build
run: |
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
Expand All @@ -199,51 +195,3 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
# verbose: true

- name: "Cache for base benchmark for ${{ github.event.pull_request.base.ref }}"
id: cache-base-bench
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref
uses: actions/cache@v4
with:
key: bench-${{ github.event.pull_request.base.ref }}
path: ./build/bench-${{ github.event.pull_request.base.ref }}.log

- name: "Benchmark"
if: inputs.benchmark == 'ON'
working-directory: ./build
run: |
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'bench' --timeout 600 -VV | tee bench.log

- name: "Checkout nats.c for ${{ github.event.pull_request.base.ref }}"
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref && steps.cache-base-bench.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
clean: false

- name: "Benchmark ${{ github.event.pull_request.base.ref }} for comparison"
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref && steps.cache-base-bench.outputs.cache-hit != 'true'
run: |
mkdir -p build
cd build
rm -rf CMakeFiles CMakeCache.txt
cmake .. ${{ steps.cmake-flags.outputs.flags }}
make rebuild_cache && make
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'bench' --timeout 600 -VV | tee bench-${{ github.event.pull_request.base.ref }}.log

- name: "Checkout HEAD ${{ github.event.pull_request.head.ref }}"
if: inputs.benchmark == 'ON' && github.event.pull_request.head.ref && steps.cache-base-bench.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
clean: false

- name: "Compare benchmark to ${{ github.event.pull_request.base.ref }}"
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref
run: |
cd build
go run ../test/diffstat_sub_async.go bench-${{ github.event.pull_request.base.ref }}.log bench.log
10 changes: 1 addition & 9 deletions .github/workflows/on-pr-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
experimental: ON
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

coverage-NO-TLS:
name: "Coverage NO-TLS"
uses: ./.github/workflows/build-test.yml
Expand All @@ -94,14 +94,6 @@ jobs:
verify_host: NO-verify_host
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

bench:
name: "Benchmark"
uses: ./.github/workflows/build-test.yml
with:
server_version: main
benchmark: ON
type: Release

Windows:
name: "Windows"
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/on-push-release-extra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
server_version: [latest, v2.9.11]
server_version: [latest, v2.10.29]
uses: ./.github/workflows/build-test.yml
name: "Other servers"
with:
Expand Down Expand Up @@ -56,10 +56,3 @@ jobs:
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

bench:
name: "Benchmark"
uses: ./.github/workflows/build-test.yml
with:
server_version: main
benchmark: ON
type: Release
26 changes: 21 additions & 5 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29606,16 +29606,21 @@ _jsPubReconnectThread(void *closure)
js_Publish(NULL, js, "foo", "hello", 5, NULL, NULL);
natsConnection_Flush(js->nc);

natsConnection_Reconnect(js->nc);
nats_Sleep(500);
natsConnection_Reconnect(js->nc);
nats_Sleep(250);

js_Publish(NULL, js, "foo", "hell1", 5, NULL, NULL);
natsConnection_Flush(js->nc);
}

void test_JetStreamSubscribePull_Reconnect(void)
{
natsStatus s;
natsStatus s = NATS_OK;
natsConnection *nc2 = NULL;
natsOptions *opts = NULL;
jsCtx *js2 = NULL;

JS_SETUP(2, 9, 2);

test("Create stream: ");
Expand All @@ -29628,14 +29633,22 @@ void test_JetStreamSubscribePull_Reconnect(void)
s = js_AddStream(NULL, js, &sc, NULL, &jerr);
testCond((s == NATS_OK) && (jerr == 0));

test("Create conn with lower reconnect wait: ");
s = natsOptions_Create(&opts);
IFOK(s, natsOptions_SetURL(opts, "nats://127.0.0.1:4222"));
IFOK(s, natsOptions_SetReconnectWait(opts, 50));
IFOK(s, natsConnection_Connect(&nc2, opts));
IFOK(s, natsConnection_JetStream(&js2, nc2, NULL));
testCond((s == NATS_OK) && (opts != NULL) && (nc2 != NULL) && (js2 != NULL));

test("Subscribe: ");
natsSubscription *sub = NULL;
s = js_PullSubscribe(&sub, js, "foo", "dur", NULL, NULL, &jerr);
s = js_PullSubscribe(&sub, js2, "foo", "dur", NULL, NULL, &jerr);
testCond(s == NATS_OK);

test("Start thread to send: ");
natsThread *t = NULL;
s = natsThread_Create(&t, _jsPubReconnectThread, (void*) js);
s = natsThread_Create(&t, _jsPubReconnectThread, (void*) js2);
testCond(s == NATS_OK);

test("Fetch request succeeds over a reconnect: ");
Expand All @@ -29651,6 +29664,9 @@ void test_JetStreamSubscribePull_Reconnect(void)
natsThread_Join(t);
natsThread_Destroy(t);
natsSubscription_Destroy(sub);
jsCtx_Destroy(js2);
natsConnection_Destroy(nc2);
natsOptions_Destroy(opts);
JS_TEARDOWN;
}

Expand Down Expand Up @@ -32776,7 +32792,7 @@ void test_KeyValueBasics(void)
kvConfig kvc;
int iterMax = 1;
int i;
char bucketName[10];
char bucketName[24];

JS_SETUP(2, 6, 2);

Expand Down
Loading