NBomber icon indicating copy to clipboard operation
NBomber copied to clipboard

How to load test using a shared feed?

Open SailorTurkey opened this issue 4 years ago • 4 comments

NBomber is perfect for static and partial dynamic load testing, but i can't find a way to load test using a shared single feed.

My case: I have a csv file with 10M product info. And an API endpoint to process them one by one. I want to load test using this feed to see how long it takes, or at least see API throughput in a 10-minute window.

But the scenarios in NBomber are using same feed (therefore duplicating product infos on API calls).

    /// For open system:
    /// Injects a given number of scenario copies at a constant rate, 
    /// defined in scenarios per second, during a given duration. 
    InjectPerSec(rate = 10, during = seconds 30)

What i need is like below, psuedo function (Inject -FROMFEED- PerSec). that takes 10 product infos from a shared feed and runs step action on them every second. I am stuck and can't find a solution to this.

Any suggestions?

   var scenario = ScenarioBuilder.CreateScenario("test product load", new[] { step })
            .WithLoadSimulations(Simulation.InjectFROMFEEDPerSec(10, TimeSpan.FromSeconds(600)));

SailorTurkey avatar Mar 09 '21 23:03 SailorTurkey

is you case covered in examples? https://github.com/PragmaticFlow/NBomber/tree/dev/examples/CSharpDev/DataFeed https://nbomber.com/docs/core-abstractions#data-feed

vilinski avatar Mar 11 '21 22:03 vilinski

Sadly no. Let me provide a clearer example. I have a single "users-feed-data.json" file with, lets say, 1000 inputs. Now i want to measure throughput simulation where there are 50 users, and each send 20 inputs to my API. Using c# Parallel.For one would implement it like below, creating a thread per "user" and split data among "users". So in short

  1. Can i implement the following procedure using NBomber?
  2. Is there a way to load-test not time-dependant but feed, where Scenario / Step stops when all items in a feed are iterated once.
        private static void Main(string[] args)
        {
            int[] sharedFeed = Enumerable.Range(0, 1000).ToArray();
            int users = 50; //users
            int feedPerCopy = sharedFeed.Length / users;

            CancellationTokenSource cts = new CancellationTokenSource();

            Parallel.For(0, users, new ParallelOptions()
            {
                MaxDegreeOfParallelism = users,
                CancellationToken = cts.Token
            }, (userIndex) =>
            {
                var valuesBelongToThisUser = sharedFeed.Skip(userIndex * feedPerCopy).Take(feedPerCopy);

                foreach (var item in valuesBelongToThisUser)
                {
                    //Call API..
                }
                Console.WriteLine($"User Id:{userIndex}, ValuesSentToAPI:{string.Join(',', valuesBelongToThisUser.Select(x => x.ToString()))}");
            });
            Console.ReadLine();
        }

image

SailorTurkey avatar Mar 12 '21 16:03 SailorTurkey

I'm afraid this isn't currently supported by NBomber out of the box, but maybe you could workaround it with ConcurrentQueue and stepContext.StopScenario(...) any time within your step execution, for example when feed queue is exhausted. PRs are also welcome

vilinski avatar Mar 13 '21 17:03 vilinski

Hi @SailorTurkey

You actually can implement this behavior by simply implementing a custom feed. Basically, you need to override GetNextItem in such a way as to return a configurable portion of data (batch).

AntyaDev avatar May 06 '21 09:05 AntyaDev