scalingasp netwebsitestomillionsofusers 120204104930 phpapp02
TRANSCRIPT
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
1/35
Scaling ASP.NET websites
from thousands to millionsof users
Omar AL ZabirChief Architect, SaaS Platform, T
omaral!abir.com
omaral!abir"gmail.com
Twitter.com#omaral!abir
oo$ %uilding &eb '.( )ortal using ASP.NET *.+ from O-eill/
Lessons learnt from scaling &eb '.( a))s to millions of users
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
2/35
0ow to blow u) a website
1et some su)er fast fiber broadband connection.
un this on cou)le of 2uad core des$to)s3
for (int j = 0; j < 100; j ++){
for (int i = 0; i < 100; i ++)
{
var client = new WebClient();
client.DownloadString!"nc(
new #ri($%tt&'www.icro!oft.co*S,e&ort.a!&-$);
/%read.Slee&(00);
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
3/35
Pre4ent A)) Le4el 5OS attac$
A))lication Le4el 5OS attac$s are attem)ts to hit/our e6)ensi4e )agestoo fre2uentl/ so that /ouha4e 7((8 CP9 and /our site goes down. :or e6,hitting some e6)ensi4e e)ort )age continuousl/.
;ou can run out of ASP.NET Threads and sto)res)onding com)letel/ to an/ re2uest.
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
4/35
Pre4ent A)) le4el 5OS attac$s
Protect onl/ e6)ensi4e )ages. Pages that are unli$el/ toget hit too man/ times within a short duration.
uild a 0tt)=odule and hoo$ on On
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
5/35
ASP.NET Process=odelO)timi!ation ASP.NET Process=odel 5efaults
ma6&or$erThreads '(
ma6
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
6/35
ASP.NET Pi)eline O)timi!ation
5efault ASP.NET Pi)eline has se4eral com)onents that interce)teach and e4er/ re2uest. Thus the/ add e6tra )rocessing o4erheadon e4er/ re2uest.
=ulti)l/ the o4erhead b/ hundreds of re2uests )er second /ouget a significant o4erhead.
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
7/35
ASP.NET Pi)eline O)timi!ation
emo4e what /ou don-t need.
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
8/35
Pre4ent large ASP.NET coo$ies onstatic content
Each and e4er/ re2uest, e4en static files, get theASP.NET coo$ies sent.
+7 b/tes of worthless data )er re2uest.
A4g )ages ha4e @( resources. @( 6 +7 '( F.
7= )age 4iew '( 1 of data u)load to ser4er.
Cookie:.5ANONw*$;c!s0?&4!sB=gr/S@G;E:(N>?ZBaLST9HFwIa1a/d5B&w905JHtN?4gKg!Ff*r*SG0usT;:K9?+/;fnun/CeuE6cZs?H+GFH:$70SB?$s1wm*D)6nZ4)5AfGFE9Fee'OTlN5(gi@*2wwt
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
9/35
Pre4ent ASP.NET coo$ies onstatic content Setu) a new website in
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
10/35
S/stem.net o)timi!ation
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
11/35
S/stem.net default setting issubo)timal
ottlenec$
=a6 ' concurrent calls
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
12/35
ASP.NET Profile Pro4ider
Anon/mous Pro4ider creates one anon/mous user indatabase on e4er/ first hit to ProfileobKect-s Custom)ro)erties3
The SP aspnet_Profile_GetPropertiesgets called when/ou access Profile obKect for first time in a re2uest. Andthis SP is slooooooooowV
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
13/35
ASP.NET Profile Pro4ider
The slow SP that gets fired when /ou access custom Profile
)ro)erties3
CEATE POCE59E dbo.as)netMProfileM1etPro)erties "A))licationName n4archar'+B, "9ser
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
14/35
ASP.NET Profile Pro4ider
The slow SP-s e6ecution )lan
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
15/35
ASP.NET Profile Pro4ider
5on-t u)date LastActivit!atewhen Profile obKect isloaded. 5o it onl/ when Profile obKect is u)dated.
9)date once e4er/ hour or so.
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
16/35
ASP.NET =embershi)
ASP.NET =embershi) Pro4ider Stored Procs use defaulttransaction isolation le4el, which is Seriali!able.
/ran!action (roce!! D 22) wa! deadloc3ed on loc3 re!o4rce!
wit% anot%er &roce!! and %a! been c%o!en a! t%e deadloc3
victi. ,er4n t%e tran!action.
/ieo4t 5-&ired. /%e /ieo4t eriod 5la&!ed rior /oCo&letion 6f /%e 6&eration 6r /%e Server ! 7ot ,e!&onding.
8/5, ,6C5D#,5 9dbo:.9a!&netrofileetro&ertie!:
&&lication7ae nvarc%ar(>?)@
#!er7ae nvarc%ar(>?)@
C4rrent/ie#tc datetie
S
A57
S5/ /,7SC/67 S68/67 85B58 ,5D #7C6**//5D;
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
17/35
ASP.NET =embershi) Duer/
Common 2ueries that brings down hell3
Select X from as)netMusers where 9serName Yblabla-
Select X from as)netMmembershi) where Email %someone"somewhere.com
&hat-s wrong with these 2ueries
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
18/35
ASP.NET =embershi) Dueries
Let[s loo$ at the inde6es3
Table3 aspnet_users
Clustered
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
19/35
A lo4e stor/
.NET *.(was released, woohooV
&C:V
Lambda E6)ressionsVV
Lin2 to SDLVVV 9)graded to .NET *.(, to) to bottom.
=aKor de)lo/ment o4er the wee$end.
=onda/ H A=, )ea$ traffic. No res)onse from site.
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
20/35
\7((8 on all web ser4ers
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
21/35
Lin2 to SDL is not suitable for high4olume web a))lications
Lin2 to SDL is not o)timi!ed for web a))lication.
No disconnected entit/ su))ort.
Entities are not seriali!able.
Lin2 to s2l e6)ressions consume high CP9 when
com)iled to SDL.
var 4er" = fro widget in dc.Widget!
w%ere widget.D == id widget.ageD == &aged
!elect widget;
var widget = 4er".Single6rDefa4lt();
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
22/35
0ow bad Lin2 to SDL is
Source3 G5 Conle/-s blog
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
23/35
:i6ing Lin2 to SDL
Con4ert all 2ueries to Com)iled Dueries.
tin/url.com#omarL
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
24/35
Lin2 to SDL transaction deadloc$s
Large table, high read and medium write, causes 2uer/timeouts, high loc$s, transaction deadloc$ because ofSE
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
25/35
Lin2 to SDL transaction deadloc$s
Connection does not closeV ug in 5ata Conte6t code.
Solution is to o4erride the 5is)ose.
c/assYourDataContext2 0YourDataContext1 &Disposab/e {
pub/ic new void Dispose() {i (base.Connection 3= nu//)i (base.Connection.!tate 3= !4stem.Data.Connection!tate.C/osed) {
base.Connection.C/ose();base.Connection.Dispose();
base.Dispose();
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
26/35
Content 5eli4er/ Networ$ C5N
C5N cache and deli4er content from their ser4ersthatare closest to users- com)uters. The closer ser4ers areto end user, the shorter roundtri) time for e4er/ re2uest.:or e6, A$amai has ser4ers almost e4er/ cit/ in theworld.
Content from C5N nodes get ser4ed faster with lower
latenc/than coming from /our ser4ers. C5N Nodes ha4e better caching and com)ression
algorithms.
C5N nodes can offload /our ser4er and networ$fromdeli4ering static files. Thus better through)ut for
d/namic content.
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
27/35
Content 5eli4er/ Networ$
(.sec
'.'sec
Australia
&ashington, 5C
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
28/35
&ithout C5N
0ome
9ser
www./oursite.com
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
29/35
0ow C5N wor$s
0ome
9ser
static./oursite.com
www./oursite.com
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
30/35
Two t/)es of C5N
Static /ou u)load the files to C5N andthe/ gi4e /ou an 9L. E.g./oursite.cachefl/.net#logo.gif
5/namic 0ost /our d/namic a))lication
behind the C5N. :or e6, Edgecast andPanther E6)ress. Ier/ chea) > ](.'#1
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
31/35
0ow 5/namic C5N wor$s
www./oursite.com
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
32/35
0ow 5/namic C5N wor$s
www./oursite.com
Static contentcached,Com)ressedautomaticall/
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
33/35
0ow 5/namic C5N wor$s
www./oursite.com
Static contentcached,Com)ressedautomaticall/
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
34/35
7* disasters for )roduction websites
1. Faulty hard drive supplied by supplier, data corruption within weeks.
2. Controller malfunctions and corrupts all disks in the same controller.
3. RA! malfunction.
". C#$ overheated and burned out.
%. Firewall went down.
&. Remote !esktop stopped workin' after a patch installation.
(. Remote !esktop ma) connection e)ceeded. Cannot lo'in anymore to
servers.
*. !atabase 'ot corrupted while we were movin' the production
database from one server to another over the network.
+. ne developer deleted the production database accidentally while
doin' routine work.
1-. upport crew at hostin' service formatted our runnin' production
server instead of a corrupted server that we asked to format.
11. /indows 'ot corrupted and was not workin' until we reinstalled.
12. !0 'oes down. !ont 'et domain from o!addy.
13. nternet backbone 'oes down in different part of the world.
http://tinyurl.com/omar13
-
7/26/2019 Scalingasp Netwebsitestomillionsofusers 120204104930 Phpapp02
35/35
Conclusion
ASP.NET out of the bo6, does not scale for millions ofhits.
=ust ma$e the hac$s at code, database andconfiguration le4el to get it to scale.
That-s realit/ for an/ technolog/, not ASP.NET s)ecific.