ASP.NET Core : Performance Testing Techniques

In this article I will be sharing some useful links and video from ON.NET SHOW which explain us performance testing techniques. I hope this could be useful to you while you are trying to perform any such performance testing on your applications.

ASP.NET Core Series: Performance Testing Techniques video

Reference links

You need to study this material to get more insights of performance testing techniques for modern .NET core 3.x applications.

I hope will help you to start !!!

Azure Service Bus Sessions

Azure Service Bus sessions enable joint and ordered handling of unbounded sequences of related messages. Sessions can be used when you want to maintain order of messages at receiver.

The basic tier of Service Bus doesn’t support sessions. The standard and premium tiers support sessions.

On session-aware queues or subscriptions, sessions come into existence when there’s at least one message with the session’s SessionId. Once a session exists, there’s no defined time or API for when the session expires or disappears. Theoretically, a message can be received for a session today, the next message in a year’s time, and if the SessionId matches, the session is the same from the Service Bus perspective.

Concurrent de-multiplexing using session

Sessions provide concurrent de-multiplexing of interleaved message streams while preserving and guaranteeing ordered delivery.

Consider a scenario, where 3 different clients are sending messages to Service Bus Queue concurrently with a unique Identifier corresponding to each client and at the receiving end, interleaved messages from each client should be received by different receivers.

FIFO Queue

When you want to deliver the messages in the same order as they are pushed in the queue. we need to send messages into session enabled queue with unique SessionId(Guid).

Queue Icons - Download Free Vector Icons | Noun Project

This will enable our Message Session Handler to read messages from queue by following First In, First Out Pattern.

How to enable session in service bus?

You can enable session on azure portal by setting the “Enable sessions” flag. This is applicable to both Queues and Topic Subscriptions.

When Sessions are enabled on a queue or a subscription, the client applications can no longer send/receive regular messages. All messages must be sent as part of a session (by setting the session id) and received by receiving the session.

Alternatively, The session enabled Azure Service Bus Queue can be created by setting the “RequireSession” property to true, using Windows Azure Service Bus library in .Net client.

How to send messages to session enabled service bus?

Sending messages to session enabled Service Bus entities is little different from entities in which session is not enabled. It is mandatory to set SessionId property in every message that is being sent.

Session are set on each message by setting a SessionId property of the brokered message. Its simple whichever message you want to be part of same session just set the same session id for them. For demo purpose, I am just setting the sessions to even and odd based on the counter.

How to receive messages from session enabled service bus?

There are multiple ways to handle session messages but in my example I will use a session handler which I feel is the most elegant way to read messages from session queue.

Register the message session handler which we will use to read the messages from session queue.


Imagine a huge stream of messages with different sessionIds. You can clearly understand how sessions can help us de-multiplexing a stream of messages.

It is also simple to implement concurrent processing for sessions. If you notice the code snippet I pasted above for Read Message With Session Handler method has a property called MaxConcurrentSessions which is currently set to 1. We can simply change this and you would see that your sessions are processed concurrently.

Source Code

Source code for this article is available at GitHub.


I hope this will help you when you want to design application where you want to maintain ordering of messages while you read messages from queue.

Spying on .NET Garbage Collector with .NET Core EventPipes

This post of the series shows how to generate GC logs in .NET Core with the new event pipes architecture and details the events emitted by the CLR during a collection.

  • Part 1: Replace .NET performance counters by CLR event tracing.
  • Part 2: Grab ETW Session, Providers and Events.
  • Part 3: CLR Threading events with TraceEvent.
  • Part 4: Spying on .NET Garbage Collector with TraceEvent.
  • Part 5: Building your own Java GC logs in .NET

To read full article click here.

I hope this will help !!!

.NET Core 2.1 – Use HttpClientFactory to implement resilient HTTP requests

The original and well-know HttpClient class can be easily used, but in some cases, it is not being properly used by many developers.

As a first issue, while this class is disposable, using it with the using statement is not the best choice because even when you dispose HttpClient object, the underlying socket is not immediately released and can cause a serious issue named ‘sockets exhaustion’.

Therefore, HttpClient is intended to be instantiated once and reused throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads. That issue will result in SocketException errors. Possible approaches to solve that problem are based on the creation of the HttpClient object as singleton or static.

But there’s a second issue with HttpClient that you can have when you use it as singleton or static object. In this case, a singleton or static HttpClient doesn’t respect DNS changes.

To address those mentioned issues and make the management of HttpClient instances easier, .NET Core 2.1 offers a new HttpClientFactory that can also be used to implement resilient HTTP calls by integrating Polly with it.

Read more…

I hope this will help !!!!


AWS API Gateway – API Creation with Lambda Proxy Integration and Web Page Redirection (302) using .NET Core 2.0

In this article, we will see how to create and test an API with Lambda proxy integration using the API Gateway console. We will also see how a Lambda backend parses the query string request and implements app logic that depends on the incoming query string parameters. we will also see how to create 302 Redirect response using Lambda function and redirect caller directly to web page.

Topic to cover in this article

  1. How to create Lambda function for Lambda Proxy Integration using .NET core 2.0?
  2. How to create Resource?
  3. How to create HTTP GET Method with Lambda Proxy Integration?
  4. How to setup Request query string parameter?
  5. How to setup Response redirect (HttpStatus=302) with Location header parameter?

Step-1: Create Lambda function for Lambda Proxy Integration using .NET core 2.0

Create New AWS Lambda Project “ApiLambdaVerifyEmail” using Visual Studio 2017 version 15.5.6:


Add following NuGet Packages for Lambda function which will be needed for API Gateway Proxy Request and Response and other Lambda features:


Update Function Handler Code with below code snippets:

public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest input, ILambdaContext context)
    //Ready query string parameter
    string queryString ;
    input.QueryStringParameters.TryGetValue("pageKey", out queryString);

    //Set Default URL if no match found
    string redirectUrl = @"";

        Console.WriteLine("pageKey : " + queryString);

    //Use Query String Parameters to do some DB Operation 

    //Based on database operation redirect page to X Web Page or Y Web Page or Z Web Page
    switch (queryString)
        case "google":
            redirectUrl = @"";
        case "twitter":
            redirectUrl = @"";
        case "sandeep":
            redirectUrl = @"";

    Console.WriteLine("URL : " + redirectUrl);

    //Redirect to Web Page using 302 Response Code and URL
    var response = new APIGatewayProxyResponse
        StatusCode = (int)HttpStatusCode.Redirect,
        Headers = new Dictionary { { "location", redirectUrl } }

    return response;


What above code does is:

  • Read query string parameters – pageKey
  • Based on query string parameter values – set redirect URLfor the response.
  • Create APIGatewayProxyResponse object with page redirection (302) Status code and add header location for the page where to redirect.

Publish Lambda function by right clicking Project on solution explorer


Next, It will display Upload Lambda function popup where you can select/define your profile, region and Lambda function name and press Next button:


Next, It will display popup to select permissions for Lambda function you are uploading and once you select Role then press Upload button:


Note: Create Role for Lambda function if you haven’t created yet using IAM console as per your Lambda function Access Requirements. For this article we are not accessing any other AWS Service from Lambda function so no role as such required.

Next step is to create API Gateway API with Lambda Proxy Integration.

Step-2: Create Resource – TestRedirectPage :

How to setup Resource guide from AWS?


Step-3: Setup GET Method with Lambda Proxy Integration: 

How to setup HTTP Method guide from AWS?


3-Add permission to lambda function-confirmation

After GET Method configuration is saved it will show all request / response configuration on screen:


Step-4: Setup Query String Parameters for API Gateway – pageKey:


Verify GET Integration Request Type is LAMBDA_PROXY:


Step-5: Setup GET Method Response redirect (HttpStatus=302) with Location header parameter:

When setting up the API Gateway Method Response, start by declaring the status code in the Method Response section. 200 will already be there so delete it. Add your 302 here instead and add the Location response header.


After above all configurations are done, Method Execution will look like:


Test GET Method we configured by clicking Test link.

  • Set Query Strings textbox “pageKey=sandeep” and press test button.


Deploy API

  • Select GET method
  • then click on Actions button on top
  • then select deploy api option
  • select/create Dev stage and press Deploy button


Get Invoke URL from Dev environment

  • select GET method of testredirectpage resource
  • then it will display invoke URL
  • by using this URL we can hit API gateway resource and execute method from browser or Postman.


Run this Invoke URL in Browsser by Adding Query String pageKey=sandeep


Browser will invoke GET API method of testredirectpage resource on API gateway and then run our lambda function endpoint, then lambda function will parse this query string value, then send response to redirect Url= , then browser will redirect page.


Similarly, you can test with other Query String parameters and see which web page opens 🙂

I hope this is useful.