Monday 25 November 2019

Tuning ASP.NET

Here are a range of articles for tuning and ASP.NET server:

Performing an await on an async operation does not use a new thread (unless the implementation explicitly starts one). It is possible to write an write to disk asynchronously without using a new worker thread. This article explains why in detail.

Task.Run, TaskFactory.StartNew and ThreadPool.QueueUserWorkItem will use a worker thread.

Contention, poor performance on ASP.NET
ASP.NET Core best practices
Tuning ASP.NET Core and avoiding large memory allocations
ASP.NET Thread usage
Tuning IIS 10
How the garbage collector causes random slowness


IO Completion Threads in more detail
IO Completion ports
Programming IOCP

Memory Management

Pooling memory buffers to avoid keep allocating memory on every request
Memory management and garbage collection
Using ArrayPool

Saturday 23 November 2019

IO at a low level

This article describes the low level interactions that make up the async process when writing to disk.

Tuesday 19 November 2019

Chaos testing Azure Service Bus with Toxiproxy


Toxiproxy runs as a docker container.

On Docker for Windows, run it in bridge networking (the default). In this the containers are isolated and so to access the port from the host it must be published. Run the container with:
docker run -it -p 8474:8474 -p 443:443 -p 5671:5671 -p 5672:5672 shopify/toxiproxy

This exposes port 8474 (the HTTP API), 443 for HTTPS and ports 5671 and 5672 for proxying Azure Service Bus on AMQP.

You can configure the proxy either by using the client SDK or by using the shell.
To attach the shell:
Docker exec -it <container ID> /bin/sh

To create a proxy for AMQP for ASB, first determine the IP address of the service.
NSLlookup <FQDN of ASB service>

In the shell type:
./toxiproxy-cli create amqp --listen --upstream <IP address of ASB service>:5671

To add upstream and downstream latency:
./toxiproxy-cli toxic add -n downlatency -t latency -a latency=8000 -d amqp

./toxiproxy-cli toxic add -n uplatency -t latency -a latency=8000 -u amqp


If you need to test any network connectivity you can use
docker run --rm -it praqma/network-multitool bash