Download Presentation - Bit-Wizards

adhocjackpotSecurity

Nov 5, 2013 (3 years and 11 months ago)

90 views

Building

Scalable ASP.NET Applications
for the Enterprise

Presented by:
Vincent W. Mayfield


President, Senior Software Engineer


MCPD, MCSD.NET, MCSD, MCTS, MCP


Vince@BitWizards.com

Vincent W. Mayfield

President / Senior Software Engineer


President/CEO & Co
-
Founder

Bit
-
Wizards Custom Software Solutions


Senior Software Engineer


18 Years Experience


15 Developing Windows Apps


MS, BS, MCPD, MCSD, MCSD.NET, MCP


USAF & US Army Veteran


Experience with Numerous Companies:

Public, Private, &
DoD


Commercial Pilot & Author


Custom Software


Software Integration


Database Development


Collaboration

Portals


Web

Design


IT

Consulting

Bit
-
Wizards creates innovative
software solutions that solve real
world business problems, allowing
our customers to be more profitable
and efficient.


Uber

Developers


Typical ASP.NET Applications


Web Farms


Clustering


Network Load Balancing


Sessions


Managing State In ASP.NET


Server Affinity


Programming Considerations
-

ASP.NET
Performance & Scalability


Review



Overview



Uber

Developers

True
Uber

Developers


Thinks in Terms of Solving Business
Problems


Understands Hardware & Software


Understands Networking


Maintains a Focus on Big Picture


Does Not Lose Sight of Details


Software Engineer


Constantly Re
-
Invents Themselves





Typical ASP.NET Applications



Monolithic

Generated Code

Server Side Code

Focuses on the Programming

No Real Planning or Design

No Real Engineering



Typical ASP.NET Application
Architecture

What Does Today’s Business Need?

Fault Tolerant

Scalable

Performance

Distributed

Enterprise
Applications

Web Farms

A web farm or server cluster, also
called a data center, is a
collection of computer servers
usually maintained by an
enterprise to accomplish server
needs far beyond the capability
of one machine.

Source: Wikipedia 2009

Clustering

A computer cluster is a group
of linked computers, working
together closely so that in
many respects they form a
single computer.

Source: Wikipedia 2009

Network Load Balancing

Types of NLBs

Hardware

Software

Which is Better?

Clustering or NLB

Web Farm Considerations


Cluster to Minimize Failures


Partition Your Database Across
Multiple Servers


Consider Affinity


Do Not User In
-
Process Session
Management

NLB Considerations


Avoid Server Affinity


Consider Stateless Components


Software or Hardware

Sessions

ASP.NET Automatically Creates a Session
for Every User that Hits a Web Server


Each Session has 10KB of Memory
Overhead + Whatever is Stored


Session Stays Alive for Configurable
Timeout Period


Sessions Do Not Span Web Servers


Managing State in ASP.NET

In
-
Process Mode

(Run on local Web Server)



State Server Mode

(Run on Remote Web Server)



SQL Server Mode

InProc

Mode

<system.web>


<
sessionState

mode="
Inproc
"


cookieless
="false"


timeout="20"/>


</
sessionState
>

</system.web>

State Server Mode

<system.web>


<
sessionState

mode="
StateServer
"


stateConnectionString
="
tcpip
=dataserver:42424"


cookieless
="false"


timeout="20"/>


</
sessionState
>

</system.web
>

SQL Server Mode

<system.web>


<
sessionState

mode="
SQLServer
"


sqlConnectionString
=


"
Integrated Security=
SSPI;data

source=
dataserver
;"


cookieless
="false"


timeout="20"/>


</
sessionState
>

</system.web>

Server Affinity

Server Affinity cont.

Two Biggest Got
Yas
!


Machine Keys


312906

HOW TO: Create Keys by Using
Visual C# .NET for Use in Forms
Authentication


Application Paths


Must

Match on All Servers


\
\
LM
\
W3SVC
\
2

Server # 1


\
\
LM
\
W3SVC
\
2

Server # 2


\
\
LM
\
W3SVC
\
2

Server # to N


Synchronization
-

DFS

Session Tips


Limit State Where you Can


Turn of Session Where You do not Need It
on a Page By Page Basis

<% @
EnableSessionState
=False %>


For Small Amounts <4KB


Cookies


Query Strings


Hidden Form Variables


For Large Amounts of Data


Use State Server


Use SQL Server


Configure Connection Pooling


Consider Data Retrieval Techniques


Query Execution Options


DataSets

vs

DataReaders


Data Paging


Design for Caching


Manage
ViewState


Compile for Release



Programming Considerations


The SQL managed provider will automatically pool
database connections


Based of the connection string


The connection strings have to match
exactly



Minor differences like extra spaces
do

matter


Specify the following parameter and values in the SQL
connection string to configure connection pooling


Max Pool Size


Min Pool Size


Remember to Close the connection to return it to

the pool!!!

Configure Connection Pooling


ADO.NET provides multiple data retrieval
techniques when a query

is executed


It is important to be aware of the results
that a query will return so that the
appropriate ADO.NET data retrieval
technique can be used

Consider Data Retrieval

Query Execution Options


ExecuteScalar



returns the first row, column
value in the result set, useful for processing
results of count, sum queries


ExecuteNonQuery



returns the result of the
query execution; Used with queries like
insert, update, delete, and DDL queries,
which don’t return results


ExecuteReader



returns a fast, forward
-
only
stream of results


DataAdapter.Fill



fills a
DataSet

with the
results of the query

DataSets


DataSet

can store a local copy of the query
results in a hierarchical format


Great for working disconnected because client
applications can treat the
DataSet

as a local database


Great for client side caching


Datasets are well suited for client side
applications, where frequent data lookups are
to be performed without querying the database


Save database round trips!

DataSets

Versus
DataReader


DataSets

are heavier than a
DataReader

for
simple, forward
-
only read operations


DataSets

are more functional than
DataReaders


DataSets

can be used as a store for query results
and act as a cache


Rich clients can use
DataSets

to avoid round
trips to the database and use
DataReaders

for
forward
-
only, read access

Data Paging


Use paged queries for a scrollable UI


Paged data access requires


Lesser network bandwidth


Faster query execution for each access


Lesser Database server memory


Lesser middle tier server memory


Better performance with queries sorted and
indexed on unique key columns


This makes the case for a clustered index!

Custom Data Paging


Requires complex query and hence more stress
on Database


Usually this a
a

fair tradeoff


More roundtrips between client and database
increasing the load on the database queries


Requires manual key tracking stored
procedures for best performance


Complex column concatenation required for
tables with no unique column

Design For Caching


Retain information in memory across HTTP
requests


Leverage the built
-
in ASP.NET built
-
in caching
features


Output Caching


Partial Page Caching


Data Caching


Recommendation:


Specifically design

your pages around these
features


can lead to massive
perf

wins

Caching Guidelines


Separate dynamic data from static data in your
pages.


Configure the memory limit.


Cache the right data.


Refresh your cache appropriately.


Cache the appropriate form of data.


Use output caching to cache relatively static pages.


Choose the right cache location.


Use
VaryBy

attributes for selective caching.


Use kernel caching on Windows Server 2003.

ViewState Management


ASP.NET controls can maintain state across round trips


State stored within “
viewstate
” hidden field


Some downsides:


Increases network payload (both on render and
postback
)


Performance overhead to serialize values to/from
viewstate


Viewstate

Flexibility:


Can disable
viewstate

entirely for a page


Can disable
viewstate

usage on a per control basis


Can use <%@ Page Trace=“true” %> to track usage size


Recommendations:


Always disable at page if you are not doing
postback

on a page

<%@ Page
EnableViewState
=“false” %>


Disable on a control if you are always re
-
generating it

on
postback

Compilation


Avoid first time page request performance
hit


Directory level batch operation


Hit each
aspx
,
ascx

or
asmx

individually

<compilation debug="
true|false
"


batch="
true|false
"


batchTimeout
="number of seconds"


maxBatchSize
="
maximim

number of pages per batched compilation"


maxBatchGeneratedFileSize
="maximum combined size (in KB) of the


generated source file per batched compilation"


Review


Design for Scalability


Know your Session


Take the Time to Optimize

Your Code Design


Questions?

Presented by:
Vincent W. Mayfield


President, Senior Software Engineer


MCPD, MCSD.NET, MCSD, MCTS, MCP


Vince@BitWizards.com

Building

Scalable ASP.NET Applications
for the Enterprise

Vincent W. Mayfield

Contact:
Vince@BitWizards.com

(850) 226
-
4200 x101


http://twitter.com/vincemayfield


http://www.linkedin.com/in/vincemayfield


http://blogs.bitwizards.com/vincent_mayfield/


http://www.codehangar.com/