Skip to content

Commit

Permalink
Aggressive Inlining v2
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Nov 29, 2022
1 parent 87d2dcb commit fe3c20b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
37 changes: 22 additions & 15 deletions src/NBomber/Api/CSharp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type Response =
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Fail() = ResponseInternal.failEmpty<obj>

static member inline Ok(
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Ok(
[<Optional;DefaultParameterValue("")>] statusCode: string,
[<Optional;DefaultParameterValue(0)>] sizeBytes: int,
[<Optional;DefaultParameterValue("")>] message: string,
Expand All @@ -33,7 +34,8 @@ type Response =
Message = if isNull message then String.Empty else message
Payload = None }

static member inline Ok<'T>(
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Ok<'T>(
[<Optional;DefaultParameterValue("")>] statusCode: string,
[<Optional;DefaultParameterValue(0)>] sizeBytes: int,
[<Optional;DefaultParameterValue("")>] message: string,
Expand All @@ -46,7 +48,8 @@ type Response =
Message = if isNull message then String.Empty else message
Payload = None }

static member inline Ok<'T>(
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Ok<'T>(
payload: 'T,
[<Optional;DefaultParameterValue("")>] statusCode: string,
[<Optional;DefaultParameterValue(0)>] sizeBytes: int,
Expand All @@ -60,7 +63,8 @@ type Response =
Message = if isNull message then String.Empty else message
Payload = Some payload }

static member inline Fail(
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Fail(
[<Optional;DefaultParameterValue("")>] statusCode: string,
[<Optional;DefaultParameterValue("")>] message: string,
[<Optional;DefaultParameterValue(0)>] sizeBytes: int,
Expand All @@ -73,7 +77,8 @@ type Response =
Message = if isNull message then String.Empty else message
Payload = None }

static member inline Fail<'T>(
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Fail<'T>(
[<Optional;DefaultParameterValue("")>] statusCode: string,
[<Optional;DefaultParameterValue("")>] message: string,
[<Optional;DefaultParameterValue(0)>] sizeBytes: int,
Expand All @@ -86,7 +91,8 @@ type Response =
Message = if isNull message then String.Empty else message
Payload = None }

static member inline Fail<'T>(
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Fail<'T>(
payload: 'T,
[<Optional;DefaultParameterValue("")>] statusCode: string,
[<Optional;DefaultParameterValue("")>] message: string,
Expand All @@ -105,7 +111,8 @@ type Step =

/// Runs a step.
/// Step represents a single user action like login, logout, etc.
static member inline Run(name: string, context: IScenarioContext, run: Func<Task<Response<'T>>>) =
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member Run(name: string, context: IScenarioContext, run: Func<Task<Response<'T>>>) =
FSharp.Step.run(name, context, run.Invoke)

/// Scenario is basically a workflow that virtual users will follow. It helps you organize steps into user actions.
Expand Down Expand Up @@ -291,8 +298,8 @@ type Simulation =
/// Injects a given number of scenario copies (threads) with a linear ramp over a given duration.
/// Every single scenario copy will iterate while the specified duration.
/// Use it for ramp up and rump down.
static member RampConstant(copies: int, during: TimeSpan) =
LoadSimulation.RampConstant(copies, during)
static member RampingConstant(copies: int, during: TimeSpan) =
LoadSimulation.RampingConstant(copies, during)

/// A fixed number of scenario copies (threads) executes as many iterations as possible for a specified amount of time.
/// Every single scenario copy will iterate while the specified duration.
Expand All @@ -302,20 +309,20 @@ type Simulation =

/// Injects a given number of scenario copies (threads) per 1 sec from the current rate to target rate during a given duration.
/// Every single scenario copy will run only once.
static member RampPerSec(rate: int, during: TimeSpan) =
LoadSimulation.RampPerSec(rate, during)
static member RampingInject(rate: int, interval: TimeSpan, during: TimeSpan) =
LoadSimulation.RampingInject(rate, interval, during)

/// Injects a given number of scenario copies (threads) per 1 sec during a given duration.
/// Every single scenario copy will run only once.
/// Use it when you want to maintain a constant rate of requests without being affected by the performance of the system under test.
static member InjectPerSec(rate: int, during: TimeSpan) =
LoadSimulation.InjectPerSec(rate, during)
static member Inject(rate: int, interval: TimeSpan, during: TimeSpan) =
LoadSimulation.Inject(rate, interval, during)

/// Injects a random number of scenario copies (threads) per 1 sec during a given duration.
/// Every single scenario copy will run only once.
/// Use it when you want to maintain a random rate of requests without being affected by the performance of the system under test.
static member InjectPerSecRandom(minRate:int, maxRate:int, during:TimeSpan) =
LoadSimulation.InjectPerSecRandom(minRate, maxRate, during)
static member InjectRandom(minRate:int, maxRate:int, interval: TimeSpan, during:TimeSpan) =
LoadSimulation.InjectRandom(minRate, maxRate, interval, during)

[<Extension>]
type OptionExtensions =
Expand Down
1 change: 1 addition & 0 deletions src/NBomber/Api/FSharp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Step =

/// Runs a step.
/// Step represents a single user action like login, logout, etc.
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
static member run (name: string, context: IScenarioContext, run: unit -> Task<Response<'T>>) = backgroundTask {

//todo: add validation on name <> Constants.ScenarioGlobalInfo
Expand Down
2 changes: 1 addition & 1 deletion src/NBomber/Domain/Scenario.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ let getMaxDuration (scenarios: Scenario list) =
let getMaxWarmUpDuration (scenarios: Scenario list) =
scenarios |> List.choose(fun x -> x.WarmUpDuration) |> List.max

let measure (name: string) (ctx: ScenarioContext) (run: IScenarioContext -> Task<IResponse>) = backgroundTask {
let inline measure (name: string) (ctx: ScenarioContext) (run: IScenarioContext -> Task<IResponse>) = backgroundTask {
let startTime = ctx.Timer.Elapsed.TotalMilliseconds
try
let! response = run ctx
Expand Down
2 changes: 1 addition & 1 deletion src/NBomber/Domain/Step.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open NBomber.Contracts.Internal
open NBomber.Domain.ScenarioContext
open NBomber.Domain.Stats.ScenarioStatsActor

let measure (name: string) (ctx: ScenarioContext) (run: unit -> Task<Response<'T>>) = backgroundTask {
let inline measure (name: string) (ctx: ScenarioContext) (run: unit -> Task<Response<'T>>) = backgroundTask {
let startTime = ctx.Timer.Elapsed.TotalMilliseconds
try
let! response = run()
Expand Down

0 comments on commit fe3c20b

Please sign in to comment.