14.01.2015 Views

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

When you run the query, it looks like this:<br />

You should do this during weekends when your traffic is lowest.<br />

However, there’s a catch. SQL Server Standard Edition does not<br />

allow online index rebuild. This means during index rebuild, the<br />

index will be offline. So, most of your queries will timeout. If you<br />

want to have the index online during the rebuild, then you will<br />

need SQL Server Enterprise Edition, which is expensive if you are<br />

on a tight budget.<br />

11<br />

Monitoring SQL Server for performance issues<br />

Windows Performance Monitor is a great way to monitor<br />

performance of your databases. Just go to Start > Run, type<br />

“perfmon” and you will get the performance monitor. From there,<br />

click on the + sign and add the following counters:<br />

These are some key counters that can give you an indication about<br />

how well your database is performing and if there’s a performance<br />

problem, what is the bottleneck.<br />

For example, here you see very high Full Scans/Sec. This means you<br />

have queries that are not using index and scanning the entire table.<br />

So, you need to investigate which queries are causing high IO and<br />

see their execution plan to find out where they are missing index.<br />

You can run SQL Server Standard Reports by right clicking on the<br />

server on SQL Server Management Studio and selecting Reports<br />

and then the Top 10 IO and Top 10 CPU consuming queries. They<br />

will show you the worst performing queries. That’s your starting<br />

point to fine tune.<br />

The other most significant one is Lock Requests/Sec. It should<br />

ideally be zero. But if you have more than 100, then it is usually<br />

bad. It is an indication that you need to put SET TRANSACTION<br />

ISOLATION LEVEL READ UNCOMMITTED in your queries.<br />

12<br />

Sending mails from websites<br />

We usually use the SmtpClient to send emails via some SMTP<br />

server. Usually you have a common email server for your company<br />

and your websites connect to that email server to send mails. But<br />

if you configure SmtpClient to connect to the mail server, then it<br />

is going to open a connection to the email server every time you<br />

call the Send() function. Establishing a SMTP session, uploading the<br />

email message, then the attachments is a very chatty process. There<br />

are many back and forth communications that happens between<br />

the webserver and email server. It makes your pages to slow down<br />

when you try to synchronously send email. If your SMTP server<br />

goes down, your website throws error and the messages are lost.<br />

Instead of configuring SMTP server settings in web.config, you<br />

should configure to use the local IIS SMTP Service. On each<br />

webserver, install the IIS SMTP Service and configure it to relay<br />

the messages to the company’s email server. This way your website<br />

will connect to the local server and queue the messages into the<br />

IIS SMTP service. Since this process happens within the server, it<br />

will be a lot faster than connecting to a distant email server. IIS<br />

SMTP service will gradually pick the messages and send them to<br />

the company’s email server.<br />

An even better approach is to use the IIS SMTP service pickup<br />

DNcmagazine www.dotnetcurry.com | 11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!