DCSIMG
March 2008 - Posts - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

March 2008 - Posts

Traceability Tool For VSTS

Recently I've talked with couple of people and they are complaining about the Tester Edition,
they say, that one of the biggest problems in the Tester Edition is the
disability to Track a Requirement Test Cover.

Why Tracking Requirement Test Cover Is Important?
Every software holds a lot of Requirements and each Requirement needs to be tested.
It's difficult to track which Requirements are covered by Test/s or not.

How can you be sure that all Requirements have been tested?

After two days of hard work, I presents the Traceability Tool Beta1.

tracetool

4 Easy Steps to Track Your Project

1. Connect to TFS and Project
2. Chose the wanted query
3. Assign to every WIT his Test/s.
4. Save

Now you have a generic report that updates continuously , just open the report to see the traceability report.

More IIS Tips

  • Patch, Patch, Patch! - Okay, we in the IIS world do have to patch our systems and make hotfixes. However, as a former Solaris admin I had to do the same thing there, so I'm not sure why this is a big surprise. You really need to keep up with the patches. Microsoft is of course the definitive source, but if you can also use the highly-regarded www.cert.org. Simply search on "IIS".

    Well there you have it: 10 tips for IIS admins to improve their servers. Some of the tips might become obsolete once IIS 6 is gold, but, for now at least, W2K and NT IIS admins should apply a few of these today and sleep a little better at night.
  • Secure Your Server with Simple Fixes - Sure people are going to attack sites, but you don't have to be a sitting duck if you're willing to make even a small effort.

    First off, don't advertise the fact that you run IIS by showing your HTTP server header. Remove or replace it using something like ServerMask -- probably the best twenty-five bucks you'll ever spend. You can go further than this by removing unnecessary file extensions to more effectively camouflage your server environment, and scanning request URLs for signs of exploits.

    There are number of commercial products that carry out user input scanning, and Microsoft offers a free tool called URLScan that does the job. URLScan runs in conjunction with IISLockDown, a standard security package that should probably be installed on every IIS server on the planet. These are simple fixes that can pay off big-time, so implement them now!

  • Tune Your Server - Tuning IIS is no small topic -- whole books and courses are dedicated to it. But some good, basic help is available online, such as this piece from IIS guru Brett Hill, or this Knowledge Base article from Microsoft itself. However, if you don't feel like getting your hands dirty -- or can't afford the time and expense of turning yourself into an expert -- take a look at XTune, from the makers of XCache. Its performance-tuning wizards step you through the process of tuning your IIS environment, and make expert recommendations along the way.
  • Customize Your Error Pages - Although this is quite simple to do, few people seem to take advantage of error page customization. Just select the "Custom Errors" tab in MMC and map each error, such as 404, to the appropriate HTML or ASP template.
    If you want an even easier solution -- or if you want to let developers handle the mapping without giving them access to the MMC -- use a product like CustomError.
  • Dive Into the MetaBase - If you think Apache is powerful because it has a config file, then take a look at the MetaBase. You can do just about anything you want with IIS by editing the MetaBase. For example, you can create virtual directories and servers; stop, start and pause Websites; and create, delete, enable and disable applications.

    Microsoft provides a GUI utility called MetaEdit, which is somewhat similar to RegEdit, to help you read from and write to the MetaBase. Download the latest version here. But to really impress those UNIX admins -- and to take full advantage of the MetaBase by learning how to manipulate it programmatically -- you'll want to try out the command-line interface, officially called the IIS Administration Script Utility. Its short name is adsutil.vbs and you'll find it in C:\inetpub\adminscripts, or in %SystemRoot%\system32\inetsrv\adminsamples, together with a host of other useful administrative scripts.

    A word of caution though: just like Apache conf files, the MetaBase is pretty crucial to the functioning of your Web server, so don't ruin it. Back it up first.
  • Add Spell Checking to Your URLs - Apache folks always brag about cool little tricks that Apache is capable of -- especially because of the wealth of modules that can extend the server's basic functionality. Among the coolest of these is the ability to fix URL typos using a module called mod_speling.

    Well, thanks to Port80 Software, it now appears that IIS admins can do this trick too, using an ISAPI filter called URLSpellCheck. You can check it out right on their site, by trying URLs like www.urlspellcheck.com/fak.htm, www.urlspellcheck.com/faq1.htm -- or any other simple typo you care to make.
  • Rewrite Your URLs - Cleaning your URLs has all sorts of benefits -- it can improve the security of your site, ease migration woes, and provide an extra layer of abstraction to your Web applications. Moving from ColdFusion to an ASP-based site, for example, is no big deal if you can remap the URLs.

    Apache users have long bragged about the huge power of mod_rewrite -- the standard Apache module for URL rewriting. Well, there are now literally a dozen versions of this type of product for IIS -- many of them quite a bit easier to use than mod_rewrite, which tends to presume familiarity with regular _expression arcana. Check out, for example, IIS ReWrite or ISAPI ReWrite. So brag no more, Apache partisans!
  • Add Browser Detection - There are many ways to build Websites, but to assume that everybody has a certain browser or screen size is just plain stupid. Simple _JavaScript sniff-scripts exist for client-side browser detection, but if you're an IIS user you can do better with a product called BrowserHawk from CyScape. The Apache world doesn't really have something comparable to this popular, mature and well-supported product.

    Speaking of CyScape, they've recently added an interesting-looking related product called CountryHawk that helps with location detection, but so far I haven't had the language- or location-sensitive content to warrant trying it out.

  • Gzip Site Content - Browsers can handle Gzipped and deflated content and decompress it on the fly. While IIS 5 had a gzip feature built-in, it's pretty much broken. Enter products like Pipeboost that give us better functionality -- similar to what Apache users have enjoyed with mod_gzip. Don't waste your bandwidth -- even Google encodes its content, and their pages are tiny.

Generate Random String

Generate Random String

If you want to generate a random value that is not an integer or CaptchaImage you can use this to generate a random string.

private string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
if (lowerCase)
{
return builder.ToString().ToLower();
return builder.ToString();
}
}

Response.Write(RandomString(4, true));

How To: Improve IIS Performance

How To: Improve IIS Performance

In my last post I talked about 10 ways to improve IIS performance, since then couple of people contact me about this post and asked me to give them my recommendations and explain them how find and configure each parameter.

So this post will be almost the same except for now I'm going to detail more about each parameter and explain how to find the right
value and configure them.

1. Enable HTTP Keep-Alives

One way to help your IIS server perform optimally is to make sure that HTTP Keep-Alives are enabled. Although IIS 6.0 enables Keep-Alives by default, this setting makes such a big difference that it’s worth it to make sure that they haven’t been turned off.

The idea behind Keep-Alives is simple. As you probably know, most Web pages are made up of multiple elements. For example, a page might consist of an HTML document and multiple images. In order to display a Web page, a Web browser must download all of the page’s various elements to a local cache. This means that most of the time, a browser must download multiple files in order to display a single Web page.

Normally, when a Web browser downloads a file, it must open a connection to the Web server, download the file, and then close the connection. Since a Web page is usually made up of multiple files, this is very inefficient. There is absolutely no reason to close the connection if the Web browser is just going to have to open it again in order to download the next file. If the HTTP Keep-Alives option is enabled, then IIS holds the connection open so that a Web browser can download multiple files without having to open and close the connection each time.

How to do it: To enable the HTTP Keep-Alives option, open the IIS Manager and navigate through the console tree to Internet Information Services |<your server>| Web Sites | your Web site. Right-click on your Web site and select the Properties command from the context menu. When you do, you will see the site’s Properties sheet (see Figure 1). The Enable HTTP Keep-Alives checkbox is located on the Web Site tab.

Enable HTTP Keep-Alives

Figure 1 Enable Keep-Alives

2. Adjust Connection Timeouts

While IIS can hold an HTTP connection open while a client downloads multiple files, you don’t want to hold the connection open indefinitely. By default, IIS 6.0 is configured to terminate a connection after 120 seconds of inactivity. This is a shorter period than was used in previous versions of IIS for a couple of reasons. First, IIS uses about 10KB of memory for each connection just to keep track of the connection. Terminating idle connections frees up memory. Second, having a short timeout period reduces the potential for denial of service attacks.

At the same time though, a 120-second idle period may or may not be optimal for your organization. Shorter timeout periods usually increase the server’s performance, but performance will degrade if a client’s connection is terminated prematurely.

The only way to determine the optimal timeout period for your server is to use the Performance Monitor to track the Current Connections, Maximum Connections, and Total Connection Attempts counters associated with the Web service performance object. Watch these counters until you have a good idea of the normal values for your organization. Then try incrementally lowering the timeout value, and watching the counters for a few days to see how they are affected. The idea is that you want to find the point at which the Current Connections and Maximum Connections counters reach their lowest average value without driving up the total connection attempts.

How to do it: You can find the timeout value on the Web Site tab of a site’s Properties sheet just below the Enable HTTP Keep-Alives checkbox. Change the value to the value you want to try.

3. Enable HTTP Compression

Another way to improve performance is to compress the pages that IIS is serving. Of course, compression can be a trade-off because it conserves bandwidth but consumes CPU time and disk space.

The trick to using compression effectively is to understand that in IIS not all files are created equal. For example, suppose that you are hosting a Web site made up mostly of static HTML pages. Compressing static pages requires a minimal effort on the part of the server because the pages can be compressed and then cached. The next time someone requests the page, IIS doesn’t have to compress it again; it can just pull the already compressed page from the cache. I recommend always compressing static pages unless your server is low on CPU resources or disk space. Dynamic pages, on the other hand, can’t really be cached. This means that IIS has to compress the dynamic pages each time that they are requested. If a site gets a lot of traffic, this can mean a lot of extra work for the server.

Just because compressed copies of dynamic pages can’t be cached does not mean that you shouldn’t compress dynamic pages. Dynamic page compression certainly does have its place. If you have a server that has a lightly used CPU, but is low on bandwidth, then it is a perfect candidate for HTTP compression.

You can compress both static and dynamic pages. In either case, you will need to verify that the temporary files are being stored in a suitable location. By default, temporary files will consume up to 95MB of space in the %windir%\IIS Temporary Compressed Files folder. When the 95MB limit has been reached, the older files will be overwritten by newer files.

How to do it: To enable HTTP compression, right-click on the Internet Information Services Manager’s Web Sites container and select the Properties command from the resulting context menu. When the Web Sites Properties sheet appears, select the Service tab. You can compress static files by selecting the Compress static files checkbox (which enables compression on htm, html, and txt files by default). Likewise, you can compress dynamic pages by selecting the Compress application files checkbox shown in Figure 2 (which enables compression on .asp, .dll, and .exe files by default). You’ll also see the option of changing the amount of space consumed by temporary files.

Enable HTTP Compression

Figure 2 Compress Application Files

You can modify the list of file extensions IIS will include in compression. To add one or more file types to the server-wide static compression configuration, open a command prompt and execute the following commands:

c:\inetpub\adminscripts>cscript adsutil.vbs 
SET W3SVC/Filters/Compression/Deflate/
HcFileExtensions "htm html txt newext" 

c:\inetpub\adminscripts>cscript adsutil.vbs 
SET W3SVC/Filters/Compression/gzip/HcFileExtensions 
"htm html txt newext"

"Newext" is the extension of the new file type you want to compress. You can add multiple file types separated by spaces.

To remove one or more file types from the server-wide static compression configuration, repeat the previous two commands, leaving out the file type you want to remove.

If you want to add one or more file types to the server-wide dynamic compression configuration, open a command prompt and type the two commands that are shown here:

c:\inetpub\adminscripts>cscript adsutil.vbs
SET W3SVC/Filters/Compression/Deflate/
HcScriptFileExtensions "asp dll exe newext"

c:\inetpub\adminscripts>cscript adsutil.vbs
SET W3SVC/Filters/Compression/gzip/
HcScriptFileExtensions "asp dll exe newext"

Once again, "newext" is the extension of the new file type you want to compress. You can add multiple file types separated by spaces. You will have to restart IIS before compression will take effect.

4. Grow a Web Garden

One way that you can increase an application pool’s performance, especially if your infrastructure includes general latency with back-end data sources, is by assigning multiple worker processes to it. The result is called a Web garden. There are a couple of benefits to Web gardens. First, they reduce resource contention. Second, if a Web application causes a worker process to hang (such as caused by a script in an infinite loop), then the other worker processes can keep servicing requests.

How to do it: You can set the number of worker processes by right-clicking on an application pool and selecting the Properties command from the resulting context menu. The Web garden setting is found on the resulting Properties sheet’s Performance tab shown in
Figure 3.

Grow a Web Garden

Figure 3 AppPool Properties

5. Adjust the IIS Object Cache TTL

IIS caches any objects that have been requested. Each object within the cache has a time to live (TTL) value associated with it. By default, the TTL value is set at 30 seconds. This means that if an object in the cache hasn’t been used in the last 30 seconds, it is removed. A 30-second TTL may not always be appropriate, however. For example, if all of the pages on your site are dynamic, then IIS doesn’t really benefit much from caching, so you could free up some memory by shortening the TTL. Likewise, if the server is short on memory, then shortening the TTL is a good way to reclaim some memory for other functions. On the other hand, if your server has plenty of free memory and most of the pages are static, then you might be able to improve efficiency by increasing the TTL.

Unfortunately, the only way of adjusting the TTL is by editing the registry. Of course if you make a serious mistake editing the registry, you can cause Windows® or your applications to fail, so make sure you have a full system backup before continuing.

How to do it: Open the Registry Editor and navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\InetInfo\Parameters. Now, right-click on the Parameters subkey and select the New | DWORD Value commands from the resulting shortcut menus. In the New Value dialog box, enter ObjectCacheTTL. Now, right-click on the value that you just created and select the Modify command. Set the base to Decimal and then enter the new TTL time (in seconds) into the Value Data box. You can set the TTL between 0 (no caching) and 4,294,967,295 (the maximum possible time limit, which indicates unlimited caching).

6. Recycle

We’ve all seen examples of poorly written code that causes memory leaks. What some people don’t realize is that Web sites can contain leaky code, too. Leaky code can really impact IIS performance over time as more and more memory drains away. One way of limiting the effects of a memory leak is to recycle the worker processes and memory at the application-pool level.

IIS recycles the worker process every 29 hours by default, but you can gain tighter control over this. You can schedule the recycle process to occur at a certain interval, a specific time of day, or after a certain number of requests. You can also configure memory to be recycled once a certain threshold has been reached.

How to do it: You can access the interface used to control recycling by right-clicking on the application pool that contains the leaky Web application, and selecting the properties command from the resulting shortcut menu. The recycling options exist on the Recycling tab of the AppPool’s Properties sheet, as you see in Figure 4.

Recycle

Figure 4 Recycling Worker Processes

7. Limit Queue Length

Queue length seems to be a touchy subject among IIS administrators, but in my opinion, it’s sometimes better to just let some visitors to your site leave rather than keep them waiting. When IIS receives a request, the request is placed into a queue and is then serviced. If requests come in more quickly than the server can service them, then the queue length grows because requests are added to the queue faster than they are being serviced. This in itself isn’t necessarily a bad thing. It’s normal for Web sites to get traffic in spurts. For example, a site might receive ten simultaneous requests one minute and only get two requests the next minute. Having a queue structure in place ensures that no requests are lost and that all of the requests are eventually serviced.

There comes a point when enough is enough though. If you’ve got 10,000 items in the queue and new requests continue to pour in, then the chances of IIS catching up with the requests any time soon are pretty slim. In these situations, it’s usually better to put a stop to new requests until the server has a chance to catch up. Imagine if there was no limit to the server’s queue length. Someone who wanted to launch a denial of service attack could flood the server with requests until the hard disk filled up. Limiting the queue length also ensures that anyone whose request is queued will be serviced within a reasonable amount of time. Everybody else will receive a notice indicating that the server is busy. Request queues service an entire application pool rather than an individual Web site.

How to do it: To change the request queue length, open the Internet Information Services Manager, right-click on the application pool that you want to adjust the queue length for, and select the Properties command from the resulting shortcut menu. When you do, you will see the AppPool’s Properties sheet that you saw in Figure 3.

The Request Queue Limit option is found on the Properties sheet’s Performance tab. By default, the queue limit is set at 1,000, but you can adjust the queue length to meet your needs.

8. Shift Priority to the Working Set

Servers running Windows Server™ 2003 are configured by default to give preference to the file system cache over the working set when allocating memory. Microsoft does this because Windows benefits from having a large file system cache. Being that IIS rides on top of the Windows operating system, it also benefits from having a large file system cache. If your server is a dedicated IIS Server, though, you might see better performance if you shift priority to the working set instead. The reason behind this is if preference is given to the file system cache, the page code is often written to virtual memory. The next time this information is needed, something else must be paged to virtual memory and the previously paged information must be read into physical memory before it can be used. This results in very slow processing.

How to do it: To shift the machine’s priority to the working set, open the Control Panel and choose the System option. When the System Properties sheet appears, select the Advanced tab and then click the Settings button found in the Performance section. This will cause Windows to display the Performance Options Properties sheet. Select the Advanced tab and then select the Programs option in the Memory usage section, as shown in Figure 5.

Shift Priority to the Working Set

Figure 5 Performance Options

9. Add Memory

The addition of physical memory is one of the best performance enhancements you can make. To optimize available memory, data is moved back and forth between RAM and disk-based virtual memory in a process known as paging. The more RAM the server machine has, the less paging will occur, and that’s good because paging is extremely inefficient and causes the machine to run much slower than it would if everything could fit into RAM. A little paging is normal, even on machines with plenty of RAM, but excessive paging will kill a machine’s performance. Not only does the machine have to stop and wait for the paging operation to complete, but the paging operation itself is processor intensive.

In addition to adding memory you can create page files on multiple hard disks. Windows requires your page file to be 1.5 times the size of your system’s RAM. However, not all of that space has to exist within a single file. For example, if you have a server with four hard drives and 1GB of RAM, then placing a 384MB page file on each of the four drives would usually be more efficient than placing a 1.5GB page file on a single disk.

10. Use Disk Striping

Although disk striping isn’t technically an IIS performance tweak, it can go a long way toward helping IIS to be more efficient. Disk striping spans files across multiple hard drives in an effort to achieve the combined performance of multiple drives. For example, if a volume is striped across five physical hard drives, then data can be read and written at approximately five times the speed that it could be if it existed on a single drive, because all five drives are being used simultaneously.

In the real world, you won’t get five times the performance by using five drives, because you lose some performance to the overhead of managing multiple drives. Some stripe sets also sacrifice some speed and capacity in order to achieve a degree of fault tolerance.

While including disk striping in your IIS architecture and design can help you achieve performance gains, unfortunately the concept of disk striping and other advanced disk configurations is a bit more complex than I’m able to discuss here. For more information, see the "Using striped volumes" section in Help and Support Center for Windows Server 2003

Hope I helped.

10 ways to improve IIS performance

10 ways to improve IIS performance

Published On: http://technet.microsoft.com/en-us/magazine/cc160755.aspx

If you want to enhance the performance of your IIS server(s) you can always cluster them or buy more bandwidth. Unfortunately, this tends to be expensive but happily there a number of ways you can improve performance without incurring these high costs.

Individually each of these may do not do much, but combined they could result in major performance gains.

  • Add more memory – To optimize available memory, data is moved back and forth between RAM and disk-based virtual memory. This process is called paging. This process is very inefficient and excessive paging will totally slow down performance. With more RAM in your server, less paging will occur and performance will be improved.
  • Enable HTTP compression – By compressing the pages that IIS is serving performance will be improved. It is important to remember that this can be a trade-off because although it conserves bandwidth, it consumes more CPU time and disk space. Consequently compression is best used on static rather than dynamic pages.
  • Adjust the IIS Object Cache TTL – Every time an object has been requested IIS caches it. Each object is given a time to live (TTL) which by default is 30 seconds. If the pages on your Web site are mostly dynamic this is not really needed, so it is possible to free up some memory by reducing the TTL. A note of warning – the only way of adjusting the TTL is by editing the registry so make sure you have a full system backup beforehand.
  • Adjust connection timeouts – IIS will hold an HTTP connection open while a client downloads multiple files and will then (by default) terminate the connection after 120 seconds of inactivity. Reducing this time out not only frees up more memory (10KB for each connection) but also reduces the potential for denial of service (DoS) attacks. However, bear in mind that 120 seconds may actually be too short for your needs. The only real way to find out what the optimal period is, is to use the Performance monitor to track connections.
  • Enable HTTP keep-alive's – A typical Web page is made up of a number of elements. Enabling HTTP keep-alive's will mean IIS keeps the connection open so the Web browser can download a page made up of different elements without having to remake a connection for each one.
  • Web garden – A Web garden is a way of increasing an application pool’s performance by assigning multiple worker processes to it. A Web garden reduces resource contention.
  • Limit queue length – When IIS receives a request it is placed into a queue until it is serviced. Normally this is not a problem but if the queue gets too long it is probably better to stop new requests until it goes down beneath a preset level. This also has the advantage of stopping your disk being filled up with requests during a DoS attack.
  • Recycle – Web sites with leaky code can seriously impact IIS performance as more memory drains away. A way round this is to recycle the worker processes and memory at the application pool level.
  • Shift priority to the working set – A server running Windows Server 2003 is configured by default to give preference to the file system cache over the working set when allocating memory. But if your server is dedicated to IIS you might see improved performance if you change the priority to the working set instead.
  • Use disk striping – Although not strictly an IIS tweak it will help IIS be more efficient.

 

Getting Associated Icons Using SHGetFileInfo in C#

Getting Associated Icons Using SHGetFileInfo in C#

This example in C# shows how to get associated icons into TreeView.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace IconsTreeViewDemo
{
    public partial class Form1 : Form
    {
        DirectoryInfo di = null;
        TreeNode nod = null;

        public Form1()
        {
            InitializeComponent();
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SHFILEINFO
        {
            public IntPtr hIcon;
            public IntPtr iIcon;
            public uint dwAttributes;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
            public string szDisplayName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
            public string szTypeName;
        };

        class Win32
        {
            public const uint SHGFI_ICON = 0x100;
            public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
            public const uint SHGFI_SMALLICON = 0x1; // 'Small icon

            [DllImport("shell32.dll")]
            public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
        }

        private void GetFoldersnFiles(DirectoryInfo di)
        {
           foreach (DirectoryInfo d in di.GetDirectories())
            {
                nod = new TreeNode(d.Name);
                nod.Name = d.FullName;
                nod.Text = d.Name;
                nod.ImageIndex = IconFind(d.FullName);

                treeView1.Nodes[0].Nodes.Add(nod);
            }
            foreach (FileInfo fi in di.GetFiles())
            {
                TreeNode f = new TreeNode(fi.Name);
                f.Name = fi.FullName;
                f.Text = f.Text;
                f.ImageIndex = IconFind(fi.FullName);
                treeView1.Nodes[0].Nodes.Add(f);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            di = new DirectoryInfo(@"C:\Windows");
            GetFoldersnFiles(di);
        }

        private int IconFind(string FileName)
        {
            IntPtr hImgSmall; //the handle to the system image list
            SHFILEINFO shinfo = new SHFILEINFO();

            hImgSmall = Win32.SHGetFileInfo(FileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
            System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
            imageList1.Images.Add(myIcon);
            int image_index = imageList1.Images.Count - 1;           
            return image_index;
        }
    }
}

You can also download the example Getting Associated Icons