Generate random throughput from x number of threads and print performance numbers at the end?

纵饮孤独 提交于 2020-06-01 05:08:23

问题


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 like x 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!