ASP.NET Core Application

infiniSoft Blog > Blog > Solution > ASP.NET Core Application

First let’s create project in Visual Studio based on .NET framework 6.0 with Docker support:

As in Java dispatcher, we’ll start with model class:

    public class Name
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public override int GetHashCode()
        {
            return FirstName.GetHashCode() ^ LastName.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType()!=typeof(Name)) return false;
            return string.Equals(FirstName, (obj as Name).FirstName) && string.Equals(LastName, (obj as Name).LastName);
        }
    }

The Business Logic:

    public class Storage
    {
        private static readonly ConcurrentDictionary<int, Name> NameSet = new();

        public static HashSet<Name> Dispatch(List<Name> Names)
        {
            HashSet<Name> resp = new HashSet<Name>();
            HashSet<Name> temp = new HashSet<Name>();

            Names.ForEach(name =>
            {
                if (NameSet.ContainsKey(name.GetHashCode()))
                {
                    resp.Add(name);
                }
                else
                {
                    temp.Add(name);
                }
            });
            foreach(Name name in temp)
            {
                NameSet.AddOrUpdate(name.GetHashCode(), name, (h, n) =>
                {
                    return n;
                });
            }

            return resp;
        }

        public static void Remove(List<Name> Names)
        {
            foreach (Name name in Names)
            {
                NameSet.Remove(name.GetHashCode(), out Name value);
            }
        }
    }

Controller would be represented as mappings under Program.cs:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapPost("/name", ([FromBody] List<Name> names) =>
{
    return Storage.Dispatch(names);
});

app.MapDelete("/name", ([FromBody] List<Name> names) =>
{
    Storage.Remove(names);
    return Task.CompletedTask;
});

app.Run();

Checking image size will show 208MB.

Before load testing application, let’s examine memory used (running docker stats will show 29.5-28.4MiB – size may differ) and then check it manually using Postman.

Repeat query to see that name excluded according to logic of dispatcher:

And now let’s clean up:

Next let’s update JMeter scenario (attached) to populate and clean up dispatcher cache based on exposed port (49153 in our example). We’ll run 100 threads in 100 cycles with 1 second ramp-up period.

On completion in 18 seconds (AMD FX-8320 with 16GB RAM) the docker stats show 126.7-119.6MiB RAM usage (size varies), and Apache JMeter:

Leave a Reply

Your email address will not be published. Required fields are marked *

About This Site

This may be a good place to introduce yourself and your site or include some credits.

Recent Comments

    Archives

    Find Us

    Mailing Address
    1703 Evans Rd 9108
    San Antonio, TX 78258

    Hours
    Monday–Friday: 9:00AM–5:00PM
    Saturday & Sunday: 11:00AM–3:00PM