-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increment/Decrement Valid Number Check (#262)
* check for valid number * wip * added IncrErrorType * added test cases & include fix for leading zero validity check * formatting * more formatting * addressing review comments * Check overflow on number load and remove benchmark * added overflow check and copyupdater validity check * first attempt bdn with embedded bench * use TryBytesLong on InitialLength calculcations * add more unit tests * fix initial length parse check
- Loading branch information
Showing
26 changed files
with
443 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System.Text; | ||
using BenchmarkDotNet.Attributes; | ||
using Embedded.perftest; | ||
using Garnet.common; | ||
using Garnet.server; | ||
|
||
namespace BDN.benchmark.Resp | ||
{ | ||
public unsafe class RespIncrementStress | ||
{ | ||
EmbeddedRespServer server; | ||
RespServerSession session; | ||
|
||
static ReadOnlySpan<byte> SINGLE_INCR => "*2\r\n$4\r\nINCR\r\n$1\r\nx\r\n"u8; | ||
static ReadOnlySpan<byte> SINGLE_DECR => "*2\r\n$4\r\nDECR\r\n$1\r\nx\r\n"u8; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
var opt = new GarnetServerOptions | ||
{ | ||
QuietMode = true | ||
}; | ||
server = new EmbeddedRespServer(opt); | ||
session = server.GetRespSession(); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
{ | ||
session.Dispose(); | ||
server.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void Increment() | ||
{ | ||
fixed (byte* ptr = SINGLE_INCR) | ||
{ | ||
_ = session.TryConsumeMessages(ptr, SINGLE_INCR.Length); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Decrement() | ||
{ | ||
fixed (byte* ptr = SINGLE_DECR) | ||
{ | ||
_ = session.TryConsumeMessages(ptr, SINGLE_DECR.Length); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(IncrByBenchInput))] | ||
public void IncrementBy(byte[] input) | ||
{ | ||
fixed (byte* ptr = input) | ||
{ | ||
_ = session.TryConsumeMessages(ptr, input.Length); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(DecrByBenchInput))] | ||
public void DecrementBy(byte[] input) | ||
{ | ||
fixed (byte* ptr = input) | ||
{ | ||
_ = session.TryConsumeMessages(ptr, input.Length); | ||
} | ||
} | ||
|
||
public static IEnumerable<object> IncrByBenchInput => values.Select(x => Get(RespCommand.INCRBY, x)); | ||
public static IEnumerable<object> DecrByBenchInput => values.Select(x => Get(RespCommand.DECRBY, x)); | ||
|
||
public static int[] values => [int.MinValue, -1, 0, int.MaxValue]; | ||
|
||
public static byte[] Get(RespCommand cmd, long val) | ||
{ | ||
var length = NumUtils.NumDigitsInLong(val); | ||
return cmd switch | ||
{ | ||
RespCommand.INCRBY => Encoding.ASCII.GetBytes($"*2\r\n$6\r\nINCRBY\r\n$1\r\nx\r\n${length}\r\n{val}\r\n"), | ||
RespCommand.DECRBY => Encoding.ASCII.GetBytes($"*2\r\n$6\r\nDECRBY\r\n$1\r\nx\r\n${length}\r\n{val}\r\n"), | ||
_ => throw new Exception($"Option {cmd} not supported") | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
namespace Garnet.server | ||
{ | ||
/// <summary> | ||
/// Operation error type | ||
/// </summary> | ||
public enum OperationError : byte | ||
{ | ||
/// <summary> | ||
/// Operation on data type succeeded | ||
/// </summary> | ||
SUCCESS, | ||
/// <summary> | ||
/// Operation failed due to incompatible type | ||
/// </summary> | ||
INVALID_TYPE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
using Garnet.common; | ||
using Tsavorite.core; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.