问题
I am working with cassandra databse and I am trying to get data from cassandra as shown below in my code. In the CassandraUtils
constructor I initialize to cassandra cluster once and then I call GetAsync
method to get data from cassandra.
public class CassandraUtils
{
public CassandraUtils(string endpoints)
{
// connect to cassandra cluster here
}
/**
*
* Below method gets data from cassandra by making multiple async calls for each clientId.
*
*/
public async Task<IList<Item>> GetAsync(IList<int> clientIds, int k, int p, Kyte kt)
{
// get data from cassandra db
}
}
Everything works fine but I want to measure my code performance and see how much time GetAsync
method is taking on average, median, 95th percentile and 99th percentile.
Questions:
I want to do below things (there might be better and thorough ideas as well but since I am a newbie so came up with below things only):
- Generate a random load on my
GetAsync
method from multiple threads which I should be able to control so that I can run this test from different variation of thread numbers and see how my code works. - Generate a particular throughput on my
GetAsync
method likex requests per seconds
and I should be able to control that so that I can run it from different variations as well if possible. - Run this whole test for particular time like
x mins
and then print the results at the end.
I recently started working with C# so trying to see how we can do this. This is just my basic understanding of how I should benchmark my GetAsync
method. If there are any other improvements we can add here then I am ok to consider that as well. Basically I just need to benchmark my GetAsync
method and I should be able to control various settings so that I can play around and see what works and what doesn't.
How should I implement this so that I can benchmark my program with different settings? I was thinking to use benchmarkdotnet here but I am not sure whether we can use it to do what I want. Any examples basis on my program will be of great help!
来源:https://stackoverflow.com/questions/62010592/generate-random-throughput-from-x-number-of-threads-and-print-performance-number