20
Alok Kumar Pandey Active Contributor - AspNetCommunity Director, Strategic Product Development at Braindigit IT Solution .NET Learnin g ASP.NET Websites From Thousands to Millions of Users facebook.com/ alokgo Facebook Twitte r @alokpandey0 1

Asp.net websites from thousands to millions of users

Embed Size (px)

DESCRIPTION

Asp.net websites from thousands to millions of users

Citation preview

Page 1: Asp.net websites from thousands to millions of users

Alok Kumar Pandey

Active Contributor - AspNetCommunity

Director, Strategic Product Development at Braindigit IT Solution

.NETLearning

ASP.NET Websites From Thousands to Millions of Users

facebook.com/alokgo

Facebook Twitter

@alokpandey01

Page 2: Asp.net websites from thousands to millions of users

Scaling Strategies for ASP.NET Applications

The Performance Equation

Scaling Problems

Optimizing the Code

Load Balancing & Affinity

Minimizing Payload & Caching

Scaling Databases

The Endless Scaling Effort

Page 3: Asp.net websites from thousands to millions of users

A Fact

.NET 3.0/4.0/4.5 was released, woohoo!

WCF!

Lambda Expressions!!

LINQ to SQL!!!, PLINQ ….

Upgraded to .NET 3.0/4.0/4.5...

Major deployment over the weekend.

Monday 9 AM, peak traffic.

No response from site.

Page 4: Asp.net websites from thousands to millions of users

The Performance Equation

The Original Performance Equation

The Web Version of the Performance Equation

• R => Response time.• Payload => Total bytes sent to the browser• Bandwidth => Rate of transfer to and from the browser. • AppTurns => The number of resource files a given page needs. • RTT => The time it takes to round-trip• Concurrent Requests => Number of simultaneous requests • Cs => Compute time on the server. • Cc => Compute time on the client.

Page 5: Asp.net websites from thousands to millions of users

Scaling Problems

Scaling:

Specialization,

Optimization, and

Distribution.

Page 6: Asp.net websites from thousands to millions of users

Optimizing the Code

Use profiling tools to analyze your application

Find out where the application is spending the most time

Page 7: Asp.net websites from thousands to millions of users

Load Balancing & Affinity

Page 8: Asp.net websites from thousands to millions of users

Minimizing Payload & Caching

Page 9: Asp.net websites from thousands to millions of users

Scaling Databases

Large-scale Web applications, partition databases into

Readers and

Writers

Page 10: Asp.net websites from thousands to millions of users

The Endless Scaling Effort

As application continues to grow, efforts to scale it are going to continue to grow as well.

Use testing to be sure spending effort where it's needed.

Test work to be sure that actually made an improvement, not just a change.

Page 11: Asp.net websites from thousands to millions of users

Facts

http://www.rootusers.com/performance-difference-between-iis-7-5-and-iis-8/

Page 12: Asp.net websites from thousands to millions of users

Which one to use

Page 13: Asp.net websites from thousands to millions of users

Speed of Common Operationsadd to end

remove from end

insert at middle

remove from middle

Random Access

In-order Access

Search for specific element

Notes

Array O(n) O(n) O(n) O(n) O(1) O(1) O(n)Most efficient use of memory; use in cases where data size is fixed.

List<T>best case O(1); worst case O(n)

O(1) O(n) O(n) O(1) O(1) O(n)Implementation is optimized for speed. In many cases, List will be the best choice.

Collection<T>best case O(1); worst case O(n)

O(1) O(n) O(n) O(1) O(1) O(n)List is a better choice, unless publicly exposed as API.

LinkedList<T> O(1) O(1) O(1) O(1) O(n) O(1) O(n)Many operations are fast, but watch out for cache coherency.

Stack<T>best case O(1); worst case O(n)

O(1) N/A N/A N/A N/A N/AShouldn't be selected for performance reasons, but algorithmic ones.

Queue<T>best case O(1); worst case O(n)

O(1) N/A N/A N/A N/A N/AShouldn't be selected for performance reasons, but algorithmic ones.

Dictionary<K,T>best case O(1); worst case O(n)

O(1)best case O(1); worst case O(n)

O(1) O(1)* O(1)* O(1)

Although in-order access time is constant time, it is usually slower than other structures due to the over-head of looking up the key.

http://www.dotnetcurry.com/ShowArticle.aspx?ID=190

Page 14: Asp.net websites from thousands to millions of users

Run this on desktops

for (int i = 0; i < 500; i ++){ for (int j = 0; j < 500; j ++) { var client = new WebClient(); client.DownloadStringAsync(new Uri("http://www.mydomain.com/page.aspx"); } Thread.Sleep(500);}

Prevent App Level DOS attack

Page 15: Asp.net websites from thousands to millions of users

ProcessModel Optimization

Servers are too powerful.

Change default process model setting in machine.config to make best use of CPU power.

Page 16: Asp.net websites from thousands to millions of users

Pipeline Optimization

Page 17: Asp.net websites from thousands to millions of users

System.net optimization

Default is 2 per IP

Page 18: Asp.net websites from thousands to millions of users

Content Delivery Network (CDN)

Content from CDN nodes get served faster with lower latency than coming from real servers.

CDN Nodes have better caching and compression algorithms.

CDN nodes can offload server and network from delivering static files. Thus better throughput for dynamic content.

Page 19: Asp.net websites from thousands to millions of users

Moral of the Story

ASP.NET out of the box, does not scale for millions of hits.

Must make the hacks at code, database and configuration level to get it to scale.

That’s reality for any technology, not only ASP.NET specific.

Page 20: Asp.net websites from thousands to millions of users

Thank You

www.aspnetcommunity.org

AspNetCommunity

ASP.NET,C#/VB.NET Developer/Programmer

LinkedIn

Facebook Group Twitter

@AspNetCommunityASP.NET Community

Facebook