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

Allow for async NBench specs #215

Open
Aaronontheweb opened this issue Jul 25, 2017 · 3 comments
Open

Allow for async NBench specs #215

Aaronontheweb opened this issue Jul 25, 2017 · 3 comments
Milestone

Comments

@Aaronontheweb
Copy link
Member

Currently I have to write:

[PerfBenchmark(
           Description =
               "Measures the throughput of Akka.Remote over a particular transport using one-way messaging",
           RunMode = RunMode.Iterations, NumberOfIterations = 3, TestMode = TestMode.Measurement,
           RunTimeMilliseconds = 1000)]
        [CounterMeasurement(RemoteMessageCounterName)]
        [GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)]
        public void PingPong(BenchmarkContext context)
        {
            _receivers.ForEach(c =>
            {
                c.Tell("hit");
            });
            var waiting = Task.WhenAll(_tasks);
            SpinWait.SpinUntil(() => waiting.IsCompleted); // TODO: would get more accurate results if we could AWAIT and not block here.
        }

What I'd like to write:

[PerfBenchmark(
           Description =
               "Measures the throughput of Akka.Remote over a particular transport using one-way messaging",
           RunMode = RunMode.Iterations, NumberOfIterations = 3, TestMode = TestMode.Measurement,
           RunTimeMilliseconds = 1000)]
        [CounterMeasurement(RemoteMessageCounterName)]
        [GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)]
        public async Task PingPong(BenchmarkContext context)
        {
            _receivers.ForEach(c =>
            {
                c.Tell("hit");
            });
            await Task.WhenAll(_tasks);
        }

Right now I'm skewing the benchmark by hogging the main thread while waiting for the background ones to finish execution. Would make for clearer results if I could do this in a non-blocking fashion and not compete for the low core-count VMs we run these benchmarks on over at Akka.NET.

@Aaronontheweb Aaronontheweb added this to the 1.5 milestone Jun 6, 2018
@Aaronontheweb Aaronontheweb modified the milestones: 2.0, 2.5 Feb 24, 2020
@BrunoZell
Copy link

What are the considerations for result accuracy here? Can we just funnel async await through NBench as is or do we need to take care of some diagnostic issues that would arise?

@jimmyheaddon
Copy link

I've just been caught out by this, as there's no obvious indication as to what is happening, other than the runner exiting before all your test code has executed. Any chance this can be introduced in the next release, or could the library possibly detect the use of async/await?

@dameng324
Copy link

waiting for supporting async/await.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants