Click here to Skip to main content
15,881,413 members
Articles / Desktop Programming / Win32
Article

Changing FileDescriptor's Limit and TIME_WAIT Limit in Win-XP, VISTA and Server2003.

Rate me:
Please Sign up or sign in to vote.
3.92/5 (9 votes)
6 Oct 2008CPOL3 min read 38.7K   864   14  
This article shows how to improve Server / System performance by changing the FILE DESCRIPTOR limit and TIME_WAIT in Windows 2003, XP and Vista.
Image 1

Introduction

This article shows how to improve Server / System performance by changing the TIME_WAIT and FILE DESCRIPTOR limit in Windows 2003, XP and Vista.

Background

Few months back, all of sudden there was a requirement from the server side team, saying that one of our server and collector-writer service is behaving sluggish as they are encountering unexpected massive volume of data and they need a fix for it very badly.

Using the Code

This article consist of two parts (1) Changing TIME_WAIT Limit and (2) Changing FILE DESCRIPTOR Limit.

Changing TIME_WAIT Limit

NETSTAT is a command which displays protocol statistics and current TCP/IP network connections. If you run a netstat -a command you will see different connection states like ESTABLISHED, LISTENING, CLOSE_WAIT... TIME_WAIT. TIME_WAIT state is the state in which a connection is waiting for the specified period of time (default is 240 seconds i.e 4 minutes) before getting closed and if there are huge number of connections in TIME_WAIT state on your Server/ System then it could limit the maximum number of connections and and reducing this TIME_WAIT default period will increase the maximum connection limit of your system. To reduce/modify the TIME_WAIT default period you need to modify the value of 'TcpTimedWaitDelay' Registry key. The value of 'TcpTimedWaitDelay' determines the length of time that a connection will stay in the TIME_WAIT state before being closed. Follow the steps given below to edit 'TcpTimedWaitDelay' settings.

Step1: Go to the Registry Key-- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
Step2: Create a new DWORD ( REG_DWORD ) value, 
       or modify the existing value called 'TcpTimedWaitDelay' if it's already there.
Step3: Set the Value between  30-300 seconds (decimal).
Step4: Exit your registry, and restart the System.

Changing FILE DESCRIPTOR Limit

FILE DESCRIPTOR Limit is the upper limit to the number of files that a program can open simultaneously. Windows has a hard upper file descriptor limit of 512 at the 'stdio level' i.e. any program can open a limited number of 512 files simultaneously at stdio level, but using the C runtime library Windows hard upper limit for file descriptors can be extended to 2048 i.e. any program can open upto 2048 number of files simultaneously using the C runtime 'setmaxstdio' call.

To change the File Descriptor's Limit, Application can use 'setmaxstdio' CRT call to change the maximum value for the number of files that might be opened simultaneously. The attached application FileDescriptor.exe uses the 'setmaxstdio' call.

The application FileDescriptor.exe has five options:

  1. Check Default File Descriptors Limit of your Platform/Configuration
    • This option enables you to checks the default File Descriptors Limit of your System
  2. Check Default File Descriptors Limit of your Platform/Configuration and verify by creating the same number of files simultaneously without using 'setmaxstdio' call.
    • This option enables you to checks the default File Descriptors Limit of your System by Creating and Opening same number of files simultaneously.
  3. Set Current File Descriptors Limit of your Platform/Configuration to:
    • This option enables you to Set the File Descriptors Limit of your System using 'setmaxstdio' call.
  4. Set Current File Descriptors Limit of your Platform/Configuration to and verify by creating the same number of files simultaneously.
    • This option enables you to Set the File Descriptors Limit of your System using 'setmaxstdio' call and allows you to Create and Open same number of files simultaneously.

    For more details look at the Source Code.

    If your application requires to open more then 2048 files simultaneously then your application should use the native Win32 API calls (E.g. CreateFile) instead of C runtime library.

  5. Number of files you wish to create and open simultaneously using WIN32 API call 'CreateFile'.
    • This option enables you to Create and Open files simultaneously using native Win32 API calls. Microsoft didn't specified any hard upper limit on the use of 'CreateFile' WIN32 API call, So you can go for hit and trial method. I succeded in Creating and Opening more than 15,000 files simultaneously at a time..

History

Initial Version 1.0.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --