Pushing the Performance of .NET Applications

y u no fast?

@marcgravell

marc@stackoverflow.com

http://marcgravell.blogspot.com

disclaimer:

everything is free

A number of tools shown here have been developed and released by Stack Exchange Inc.

They are all completely free; nobody is trying to sell you anything.

Part 1 : .NET

  • performance is a feature
  • mini-profiler
  • dapper
  • opserver

Part 2 : Redis

  • introduction and motivations
  • management
  • coding from .NET
  • scaling out
  • life in the cloud

Part 1 : .NET

performance is a feature

poor selection of tools

  • too coarse: can't dig into the data
  • too fine: further disrupts performance; too much data

mini-profiler

  • lightweight and extensible profiler
  • can leave on 24x7 in production
  • flexible security, persistence, etc
  • you tell it what to do; elective granularity
  • core usable in multiple project types; includes ASP.NET hooks
  • includes SQL profiling
  • automatic AJAX hooking
Demo 0

installation

PM> Install-Package MiniProfiler.Mvc4
Demo 1
Demo 2
Demo 3

dapper

  • micro-ORM
  • db-agnostic
  • raw SQL: get to love it
  • pain-free parameterization
  • fast materialization

installation

PM> Install-Package Dapper

advantages

  • easy to get right
  • type safe
  • null vs DbNull vs Nullable<T>
  • in @idsin (@ids0,…,@ids7)
Demo 4

opserver

  • multi-purpose monitoring tool
  • inbuilt support for SQL
  • inbuilt support for Redis

installation

https://github.com/opserver/Opserver

download, configure, run

Part 2: Redis

introduction and motivations

  • high performance key-value store
  • core structures:
    • strings
    • hashes
    • lists
    • sets
    • sorted sets
    • pub/sub

fast

no, really: fast

installation

http://redis.io/download

$ wget http://download.redis.io/releases/redis-2.8.9.tar.gz
$ tar xzf redis-2.8.9.tar.gz
$ cd redis-2.8.9
$ sudo make install
                        

PM> Install-Package Redis-64

C:\> cinst redis-64

management

coding from .NET

installation

PM> Install-Package StackExchange.Redis

scaling out

Single Master

Master / Slave

Chained Slaves

Sharded

Proxied

Cluster

cluster features

  • distributed keyspace
  • live resharding
    • redirection (not proxying)
  • HA fault tolerance
  • node discovery
  • "hash tags" allow same-node control: "{/users/12345}/balance" vs "{/users/12345}/credits"

cluster restrictions

  • requires cluster-aware client
  • multiple databases not supported
  • all multi-key commands must be on same node
  • some commands must now be considered per-server
    • keys, scan, flushdb, flushall
  • chained replication not supported
    • multi-DC not recommended

cluster installation

your.conf

port {n}
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
daemonize yes

redis-trib.rb

$ ./redis-trib.rb create --replicas {n} {server0:port0}
{server1:port1} {server2:port2} …

life in the cloud

providers

this list is for information only -
it is neither exhaustive nor a statement of service quality

Questions?

These slides are available:
http://marcgravell.com/

Or, contact me:

@marcgravell

marc@stackoverflow.com

http://marcgravell.blogspot.com