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

Added BDN for all Sorted Set commands #991

Merged
merged 8 commits into from
Feb 7, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-bdnbenchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
os: [ ubuntu-latest, windows-latest ]
framework: [ 'net8.0' ]
configuration: [ 'Release' ]
test: [ 'Operations.BasicOperations', 'Operations.ObjectOperations', 'Operations.HashObjectOperations', 'Cluster.ClusterMigrate', 'Cluster.ClusterOperations', 'Lua.LuaScripts', 'Lua.LuaScriptCacheOperations','Lua.LuaRunnerOperations','Operations.CustomOperations', 'Operations.RawStringOperations', 'Operations.ScriptOperations', 'Operations.ModuleOperations', 'Operations.PubSubOperations', 'Network.BasicOperations', 'Network.RawStringOperations' ]
test: [ 'Operations.BasicOperations', 'Operations.ObjectOperations', 'Operations.HashObjectOperations', 'Operations.SortedSetOperations', 'Cluster.ClusterMigrate', 'Cluster.ClusterOperations', 'Lua.LuaScripts', 'Lua.LuaScriptCacheOperations','Lua.LuaRunnerOperations','Operations.CustomOperations', 'Operations.RawStringOperations', 'Operations.ScriptOperations', 'Operations.ModuleOperations', 'Operations.PubSubOperations', 'Network.BasicOperations', 'Network.RawStringOperations' ]
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
11 changes: 0 additions & 11 deletions benchmark/BDN.benchmark/Operations/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace BDN.benchmark.Operations
[MemoryDiagnoser]
public unsafe class ObjectOperations : OperationsBase
{
static ReadOnlySpan<byte> ZADDREM => "*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nc\r\n*3\r\n$4\r\nZREM\r\n$1\r\nc\r\n$1\r\nc\r\n"u8;
Request zAddRem;

static ReadOnlySpan<byte> LPUSHPOP => "*3\r\n$5\r\nLPUSH\r\n$1\r\nd\r\n$1\r\ne\r\n*2\r\n$4\r\nLPOP\r\n$1\r\nd\r\n"u8;
Request lPushPop;

Expand All @@ -25,22 +22,14 @@ public override void GlobalSetup()
{
base.GlobalSetup();

SetupOperation(ref zAddRem, ZADDREM);
SetupOperation(ref lPushPop, LPUSHPOP);
SetupOperation(ref sAddRem, SADDREM);

// Pre-populate data
SlowConsumeMessage("*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8);
SlowConsumeMessage("*3\r\n$5\r\nLPUSH\r\n$1\r\nd\r\n$1\r\nf\r\n"u8);
SlowConsumeMessage("*3\r\n$4\r\nSADD\r\n$1\r\ne\r\n$1\r\nb\r\n"u8);
}

[Benchmark]
public void ZAddRem()
{
Send(zAddRem);
}

[Benchmark]
public void LPushPop()
{
Expand Down
166 changes: 166 additions & 0 deletions benchmark/BDN.benchmark/Operations/SortedSetOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;
using Embedded.server;

namespace BDN.benchmark.Operations
{
/// <summary>
/// Benchmark for SortedSetOperations
/// </summary>
[MemoryDiagnoser]
public unsafe class SortedSetOperations : OperationsBase
{
static ReadOnlySpan<byte> ZADDREM => "*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nc\r\n*3\r\n$4\r\nZREM\r\n$1\r\nc\r\n$1\r\nc\r\n"u8;
static ReadOnlySpan<byte> ZCARD => "*2\r\n$5\r\nZCARD\r\n$1\r\nc\r\n"u8;
static ReadOnlySpan<byte> ZCOUNT => "*4\r\n$6\r\nZCOUNT\r\n$1\r\nc\r\n$1\r\n0\r\n$1\r\n2\r\n"u8;
static ReadOnlySpan<byte> ZDIFF => "*4\r\n$5\r\nZDIFF\r\n$1\r\n2\r\n$1\r\nc\r\n$1\r\nh\r\n"u8;
static ReadOnlySpan<byte> ZDIFFSTORE => "*5\r\n$10\r\nZDIFFSTORE\r\n$4\r\ndest\r\n$1\r\n2\r\n$1\r\nc\r\n$1\r\nh\r\n"u8;
static ReadOnlySpan<byte> ZINCRBY => "*4\r\n$7\r\nZINCRBY\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZINTER => "*4\r\n$6\r\nZINTER\r\n$1\r\n2\r\n$1\r\nc\r\n$1\r\nh\r\n"u8;
static ReadOnlySpan<byte> ZINTERCARD => "*4\r\n$10\r\nZINTERCARD\r\n$1\r\n2\r\n$1\r\nc\r\n$1\r\nh\r\n"u8;
static ReadOnlySpan<byte> ZINTERSTORE => "*5\r\n$11\r\nZINTERSTORE\r\n$4\r\ndest\r\n$1\r\n2\r\n$1\r\nc\r\n$1\r\nh\r\n"u8;
static ReadOnlySpan<byte> ZLEXCOUNT => "*4\r\n$9\r\nZLEXCOUNT\r\n$1\r\nc\r\n$1\r\n-\r\n$1\r\n+\r\n"u8;
static ReadOnlySpan<byte> ZMPOP => "*4\r\n$5\r\nZMPOP\r\n$1\r\n1\r\n$1\r\nc\r\n$3\r\nMIN\r\n*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZMSCORE => "*3\r\n$7\r\nZMSCORE\r\n$1\r\nc\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZPOPMAX => "*2\r\n$7\r\nZPOPMAX\r\n$1\r\nc\r\n*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZPOPMIN => "*2\r\n$7\r\nZPOPMIN\r\n$1\r\nc\r\n*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZRANDMEMBER => "*2\r\n$10\r\nZRANDMEMBER\r\n$1\r\nc\r\n"u8;
static ReadOnlySpan<byte> ZRANGE => "*4\r\n$6\r\nZRANGE\r\n$1\r\nc\r\n$1\r\n0\r\n$1\r\n1\r\n"u8;
static ReadOnlySpan<byte> ZRANGESTORE => "*5\r\n$11\r\nZRANGESTORE\r\n$4\r\ndest\r\n$1\r\nc\r\n$1\r\n0\r\n$1\r\n1\r\n"u8;
static ReadOnlySpan<byte> ZRANK => "*3\r\n$5\r\nZRANK\r\n$1\r\nc\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZREMRANGEBYLEX => "*4\r\n$14\r\nZREMRANGEBYLEX\r\n$1\r\nc\r\n$1\r\n-\r\n$1\r\n+\r\n*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZREMRANGEBYRANK => "*4\r\n$15\r\nZREMRANGEBYRANK\r\n$1\r\nc\r\n$1\r\n0\r\n$1\r\n1\r\n*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZREMRANGEBYSCORE => "*4\r\n$16\r\nZREMRANGEBYSCORE\r\n$1\r\nc\r\n$1\r\n0\r\n$1\r\n2\r\n*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZREVRANK => "*3\r\n$8\r\nZREVRANK\r\n$1\r\nc\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZSCAN => "*6\r\n$5\r\nZSCAN\r\n$1\r\nc\r\n$1\r\n0\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n"u8;
static ReadOnlySpan<byte> ZSCORE => "*3\r\n$6\r\nZSCORE\r\n$1\r\nc\r\n$1\r\nd\r\n"u8;
static ReadOnlySpan<byte> ZUNION => "*4\r\n$6\r\nZUNION\r\n$1\r\n2\r\n$1\r\nc\r\n$1\r\nh\r\n"u8;
static ReadOnlySpan<byte> ZUNIONSTORE => "*5\r\n$11\r\nZUNIONSTORE\r\n$4\r\ndest\r\n$1\r\n2\r\n$1\r\nc\r\n$1\r\nh\r\n"u8;

Request zAddRem, zCard, zCount, zDiff, zDiffStore, zIncrby, zInter, zInterCard,
zInterStore, zLexCount, zMPop, zMScore, zPopMax, zPopMin,
zRandMember, zRange, zRangeStore, zRank, zRemRangeByLex,
zRemRangeByRank, zRemRangeByScore, zRevRank, zScan,
zScore, zUnion, zUnionStore;

public override void GlobalSetup()
{
base.GlobalSetup();

SetupOperation(ref zAddRem, ZADDREM);
SetupOperation(ref zCard, ZCARD);
SetupOperation(ref zCount, ZCOUNT);
SetupOperation(ref zDiff, ZDIFF);
SetupOperation(ref zDiffStore, ZDIFFSTORE);
SetupOperation(ref zIncrby, ZINCRBY);
SetupOperation(ref zInter, ZINTER);
SetupOperation(ref zInterCard, ZINTERCARD);
SetupOperation(ref zInterStore, ZINTERSTORE);
SetupOperation(ref zLexCount, ZLEXCOUNT);
SetupOperation(ref zMPop, ZMPOP);
SetupOperation(ref zMScore, ZMSCORE);
SetupOperation(ref zPopMax, ZPOPMAX);
SetupOperation(ref zPopMin, ZPOPMIN);
SetupOperation(ref zRandMember, ZRANDMEMBER);
SetupOperation(ref zRange, ZRANGE);
SetupOperation(ref zRangeStore, ZRANGESTORE);
SetupOperation(ref zRank, ZRANK);
SetupOperation(ref zRemRangeByLex, ZREMRANGEBYLEX);
SetupOperation(ref zRemRangeByRank, ZREMRANGEBYRANK);
SetupOperation(ref zRemRangeByScore, ZREMRANGEBYSCORE);
SetupOperation(ref zRevRank, ZREVRANK);
SetupOperation(ref zScan, ZSCAN);
SetupOperation(ref zScore, ZSCORE);
SetupOperation(ref zUnion, ZUNION);
SetupOperation(ref zUnionStore, ZUNIONSTORE);

// Pre-populate data for two sorted sets
SlowConsumeMessage("*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8);
SlowConsumeMessage("*6\r\n$4\r\nZADD\r\n$1\r\nh\r\n$1\r\n1\r\n$1\r\nd\r\n$1\r\n2\r\n$1\r\ne\r\n"u8);
SlowConsumeMessage("*4\r\n$4\r\nZADD\r\n$4\r\ndest\r\n$1\r\n1\r\n$1\r\nd\r\n"u8);
}

[Benchmark]
public void ZAddRem()
{
Send(zAddRem);
}

[Benchmark]
public void ZCard() => Send(zCard);

[Benchmark]
public void ZCount() => Send(zCount);

[Benchmark]
public void ZDiff() => Send(zDiff);

[Benchmark]
public void ZDiffStore() => Send(zDiffStore);

[Benchmark]
public void ZIncrby() => Send(zIncrby);

[Benchmark]
public void ZInter() => Send(zInter);

[Benchmark]
public void ZInterCard() => Send(zInterCard);

[Benchmark]
public void ZInterStore() => Send(zInterStore);

[Benchmark]
public void ZLexCount() => Send(zLexCount);

[Benchmark]
public void ZMPop() => Send(zMPop);

[Benchmark]
public void ZMScore() => Send(zMScore);

[Benchmark]
public void ZPopMax() => Send(zPopMax);

[Benchmark]
public void ZPopMin() => Send(zPopMin);

[Benchmark]
public void ZRandMember() => Send(zRandMember);

[Benchmark]
public void ZRange() => Send(zRange);

[Benchmark]
public void ZRangeStore() => Send(zRangeStore);

[Benchmark]
public void ZRank() => Send(zRank);

[Benchmark]
public void ZRemRangeByLex() => Send(zRemRangeByLex);

[Benchmark]
public void ZRemRangeByRank() => Send(zRemRangeByRank);

[Benchmark]
public void ZRemRangeByScore() => Send(zRemRangeByScore);

[Benchmark]
public void ZRevRank() => Send(zRevRank);

[Benchmark]
public void ZScan() => Send(zScan);

[Benchmark]
public void ZScore() => Send(zScore);

[Benchmark]
public void ZUnion() => Send(zUnion);

[Benchmark]
public void ZUnionStore() => Send(zUnionStore);
}
}
80 changes: 80 additions & 0 deletions test/BDNPerfTests/BDN_Benchmark_Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,86 @@
"expected_HStrLen_None": 6400,
"expected_HVals_None": 3200
},
"BDN.benchmark.Operations.SortedSetOperations.*": {
"expected_ZAddRem_ACL": 18400,
"expected_ZCard_ACL": 0,
"expected_ZCount_ACL": 0,
"expected_ZDiff_ACL": 0,
"expected_ZDiffStore_ACL": 0,
"expected_ZIncrby_ACL": 0,
"expected_ZInter_ACL": 0,
"expected_ZInterCard_ACL": 0,
"expected_ZInterStore_ACL": 0,
"expected_ZLexCount_ACL": 0,
"expected_ZMPop_ACL": 6400,
"expected_ZMScore_ACL": 0,
"expected_ZPopMax_ACL": 6400,
"expected_ZPopMin_ACL": 6400,
"expected_ZRandMember_ACL": 1184,
"expected_ZRange_ACL": 0,
"expected_ZRangeStore_ACL": 0,
"expected_ZRank_ACL": 0,
"expected_ZRemRangeByLex_ACL": 6400,
"expected_ZRemRangeByRank_ACL": 6400,
"expected_ZRemRangeByScore_ACL": 6400,
"expected_ZRevRank_ACL": 0,
"expected_ZScan_ACL": 776,
"expected_ZScore_ACL": 0,
"expected_ZUnion_ACL": 0,
"expected_ZUnionStore_ACL": 0,
"expected_ZAddRem_AOF": 18400,
"expected_ZCard_AOF": 3200,
"expected_ZCount_AOF": 20000,
"expected_ZDiff_AOF": 25600,
"expected_ZDiffStore_AOF": 27200,
"expected_ZIncrby_AOF": 12000,
"expected_ZInter_AOF": 34400,
"expected_ZInterCard_AOF": 34400,
"expected_ZInterStore_AOF": 123200,
"expected_ZLexCount_AOF": 66400,
"expected_ZMPop_AOF": 59201,
"expected_ZMScore_AOF": 6400,
"expected_ZPopMax_AOF": 48001,
"expected_ZPopMin_AOF": 48001,
"expected_ZRandMember_AOF": 1184,
"expected_ZRange_AOF": 28000,
"expected_ZRangeStore_AOF": 12800,
"expected_ZRank_AOF": 13600,
"expected_ZRemRangeByLex_AOF": 111201,
"expected_ZRemRangeByRank_AOF": 84801,
"expected_ZRemRangeByScore_AOF": 84001,
"expected_ZRevRank_AOF": 13600,
"expected_ZScan_AOF": 776,
"expected_ZScore_AOF": 6400,
"expected_ZUnion_AOF": 34400,
"expected_ZUnionStore_AOF": 129600,
"expected_ZAddRem_None": 18400,
"expected_ZCard_None": 3200,
"expected_ZCount_None": 20000,
"expected_ZDiff_None": 25600,
"expected_ZDiffStore_None": 27200,
"expected_ZIncrby_None": 12000,
"expected_ZInter_None": 34400,
"expected_ZInterCard_None": 34400,
"expected_ZInterStore_None": 79200,
"expected_ZLexCount_None": 66400,
"expected_ZMPop_None": 59201,
"expected_ZMScore_None": 6400,
"expected_ZPopMax_None": 48001,
"expected_ZPopMin_None": 48001,
"expected_ZRandMember_None": 1184,
"expected_ZRange_None": 28000,
"expected_ZRangeStore_None": 12800,
"expected_ZRank_None": 13600,
"expected_ZRemRangeByLex_None": 111201,
"expected_ZRemRangeByRank_None": 84801,
"expected_ZRemRangeByScore_None": 84001,
"expected_ZRevRank_None": 13600,
"expected_ZScan_None": 776,
"expected_ZScore_None": 6400,
"expected_ZUnion_None": 34400,
"expected_ZUnionStore_None": 84800
},
"BDN.benchmark.Cluster.ClusterOperations.*": {
"expected_Get_DSV": 0,
"expected_Set_DSV": 0,
Expand Down
13 changes: 9 additions & 4 deletions test/BDNPerfTests/run_bdnperftest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

NOTE: The expected values are specific for the CI Machine. If you run these on your machine, you will need to change the expected values.

NOTE: If adding a new BDN perf test to the BDN_Benchmark_Config.json, then need to add to the "test: [..." line in the ce-bdnbenchmark.yml
NOTE: If adding a new BDN perf test to the BDN_Benchmark_Config.json, then need to add to the "test: [..." line in the ci-bdnbenchmark.yml

.EXAMPLE
./run_bdnperftest.ps1
Expand Down Expand Up @@ -140,7 +140,7 @@ $testProperties = $json.$currentTest

# create a matrix of expected results for specific test
$splitTextArray = New-Object 'string[]' 3
$expectedResultsArray = New-Object 'string[,]' 70, 3
$expectedResultsArray = New-Object 'string[,]' 100, 3

[int]$currentRow = 0

Expand Down Expand Up @@ -216,11 +216,16 @@ $testSuiteResult = $true
Get-Content $resultsFile | ForEach-Object {
$line = $_

# Skip lines that don't start with |
if (-not $line.StartsWith("|")) {
return
}

# Get a value
for ($currentExpectedProp = 0; $currentExpectedProp -lt $totalExpectedResultValues; $currentExpectedProp++) {

# Check if the line contains the method name
if ($line -match [regex]::Escape($expectedResultsArray[$currentExpectedProp, 0])) {
# Check if the line contains the exact method name by using word boundaries
if ($line -match [regex]::Escape($expectedResultsArray[$currentExpectedProp, 0]) + "\b") {

# Found the method in the results, now check the param we looking for is in the line
if ($line -match [regex]::Escape($expectedResultsArray[$currentExpectedProp, 1])) {
Expand Down