???? ID: 156932 - ????? ???????: 02 ?????? 2010 - ??????: 4.0

I/O ?????????? ????? ?? Windows NT, Windows 2000 ?? Windows XP ????????? ????? ??

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

Microsoft Windows NT, Windows 2000 ?? Windows XP ?? i/O ????? ????????? ?? ?????????? ?? ???? ??? I/O ?? ??? ??????? ??????? ?? ????????? ??: ?? i/O ?????? ??? ???? ?? ?? i/O ?? ???? ???? ???? ??? ?????????? i/O, ?? ????? ???, ???????? ?? ????? ???? ?? ???? ???? ?? ??? ??? i/O ?????? ???? ??, ????? ?????? ?? ??? ??? ?? ???? ???? ?? ??? i/O assumed ???? ??? ???????? ?????? ???? i/O ???? ?? ???? ?? ?? ????? ???? ??? ???????? ??? ??, ???? ???????? ?????? ?? ?????? ?? ????? ???? ????? i/O ???????? ?? ?????? ????????? ?? ???? ????

?????????? i/O ?? ??? ???? ?? ???? ????? ???? ??? ?? ???? ???????? ?? ????? i/O ???????? ?? ????? ???? ?? ??? ?? ?? ???? ?? ??? ??? ??? ?? Overlapped i/O ????? ????? ??? ?? ?????????? i/O ?? ???-overlapped i/O ?? ??? ????????? i/O ?? ???? ?? ???? Windows NT ?? ??????? i/O ???????? ?? ??? ?????? Asynchronous ?? Synchronous ?? ????? ???? ??? ?? ???? ???? ?? ???? CreateFile, ReadFile, WriteFile ????? i/O ?????? ?? ??? ??? familiarity ????? ???

?????, ?????????? i/O ???????? ??????? ?? ??? ??? ????????? ???? i/O. ??? ????????? ?? ?? ?? ???? ??? ??? ??? ?????? ??? i/O ???????? synchronously ????? ????? ???? ??? ??? ???? ???? ?? ????????? ????? ?? ??? ??? ??? ?? ??????? i/O ?????? i/O ????? ???? ?? ???? ?????

?? ?????? ????????? ?? ?????????? i/O ?? ??????? ???? ?? ???? ???? ReadFile ?? WriteFile ?????? ?? ??? ???; ???? ????? ?????? ReadFileEx ?? WriteFileEx ???? ??? ?????? ?? ???? ?? ????? ???? ???? ????? i/O ????? ??? ??, ?? principles ???? ???? ?? ???? i/O, ???? ?????? i/O ?? i/O ??????? ?? ???? ???????? ?? ????

???:: ??????? Windows 95 ?? ?????? ???? ???? ?????????? i/O ????? ?????? (?????? ?? ???? ?????? ?? ??/? ?????? ?? ??), ???? ??????? ?? ?? ???? ??? ????? ???? ???

???? ???????

?????????? i/O ??? ????

?? ???? ???? ?? FILE_FLAG_OVERLAPPED ????? ?? CreateFile ??? ????????? ???? ?????? ??? ?? ???? asynchronously ???? ???? ?? ??? ????? ?? i/O ???????? ?? ?????? ???? ??? ???? ?? ?????? ??:
   HANDLE hFile;

   hFile = CreateFile(szFileName,
                      GENERIC_READ,
                      0,
                      NULL,
                      OPEN_EXISTING,
                      FILE_FLAG_NORMAL | FILE_FLAG_OVERLAPPED,
                      NULL);

   if (hFile == INVALID_HANDLE_VALUE)
      ErrorOpeningFile();
				
?? ?????? ?? ???? ?? ??? ???????? ???? ?? ???????? ?? ??? ????????? ????? ?? ??? ??????? ???? ?? ??????? ?????????? i/O ?? ??? ?????? careful ?? ????? ?????, ??? ??????????? ?? ??? ?? ????????? ?? ??? ?? synchronously ?? asynchronously ????? ???? ?? ???? ?? ?? i/O ???????? ?? ???? ???? ?? ??? ?????? ????? ??? ????????? ???? ?? ?? ?? consideration ?????

???? ?? ????? ?? ???? ??? ??? ????????? ???? ?????????? ???????? ?? ????? ???? ?? ???, ???? ?????????? ???????? ????????, ?? ??? ????????? ?? ??? ?? ?? ????????? ????? ?? ??? ???? ?????? ?? ???, ????? ??? ??? ????? ?? ??????? ?? ??? ???????? ?? overlapped ?? ???-overlapped ?????? ?? ??? ???? ?? ?? ???? i/o ????? ?????? ????? ???? ?? ??? ????????? ????:
   if (!ReadFile(hFile,
                 pDataBuf,
                 dwSizeOfBuffer,
                 &NumberOfBytesRead,
                 &osReadOperation )
   {
      if (GetLastError() != ERROR_IO_PENDING)
      {
         // Some other error occurred while reading the file.
         ErrorReadingFile();
         ExitProcess(0);
      }
      else
         // Operation has been queued and
         // will complete in the future.
         fOverlapped = TRUE;
   }
   else
      // Operation has completed immediately.
      fOverlapped = FALSE;

   if (fOverlapped)
   {
      // Wait for the operation to complete before continuing.
      // You could do some background work if you wanted to.
      if (GetOverlappedResult( hFile,
                               &osReadOperation,
                               &NumberOfBytesTransferred,
                               TRUE))
         ReadHasCompleted(NumberOfBytesTransferred);
      else
         // Operation has completed, but it failed.
         ErrorReadingFile();
   }
   else
      ReadHasCompleted(NumberOfBytesRead);
				
????? ??? ?? & NumberOfBytesRead ReadFile ??? ???? ?? ????? ?? ?? NumberOfBytesTransferred GetOverlappedResult ??? ???? ??? ??? ??? ??? ???????? ??? ??? ?? ??????????, ?? GetOverlappedResult ????? ??? ?? ???????? ???????? ??? ??????????? ???? ?? ??? ????? ?? ???? ?? ?????? ?? ?????? ????????? ???? ?? ???? & Meaningless NumberOfBytesRead ReadFile ??? ???? ??? ???

???, ?? ????? ???, ??? ???????? ????? ???? ?????, ?? & NumberOfBytesRead ??? ???? ReadFile ??? ?????? ?? ?????? ?? ??? ????? ??? ?? ?????? ???, ReadFile ??? ???? OVERLAPPED ?????? ?? ????? ? ???; ????? ???? ???? ?? GetOverlappedResult ?? WaitForSingleObject ?? ??? ?????? ?????

?????????? ???????? ?? ??? ???? caveat ?? ?? ?? ?????? ???? ????? ??? OVERLAPPED ?????? ?? ???? ????? ???????? ????? ?? ???? ??? ????? ?????? ???, ??? ???? ??? ??? ????? i/O ???????? ??, ?? ?? ????? ???? ????? ??? OVERLAPPED ???????? ???? ??? ?? ???? OVERLAPPED ?????? ?? ???: ?????, ?? i/O ???????? ??? ????????? ?????? ??????? ?????? ?? ???? ????? ????? ?? ???? ???? ??? ??, ???? ???? ?? ?? ???? ??? ?? ??? ??? OVERLAPPED ?????? ?? ????? ?? ????, ?? ???: ?? ????? ??? ?? ????? ???????? ????? ???? ?? ??? ?? ????, ?? ??? ?? ??????? ???? ?????? ??? ????-??? ???? ??? ??? ???????? ???????? ???? ?? ??????

???? ???? ??? ?? ????????? ?? ????? ???? ?? ??? ???????? ?? ?? ?? ?????? ???? ???? ??? ???? ???? ???? ?????? ???? ???? ?? ???? ????? ?? ???? ???? ?? ?? ?? ?? ???? ??????? i/O ???????? ????? ?? ???? ??; ???? ?? ???? ????? ???? ????????? ?? ????? ?????

?????????? i/O ??? ?? ???? Synchronous ???? ?? ???? ??

??? ?? ???? ?? ???? ??? ??? ????????? ?? ???? ???, ??? ??, ???? ??? i/O ???????? ?????????? ??? ?? ????? synchronously ???? ???? ??? ??, ???? ??? ?? ?? ReadFile ???????? ???? FALSE ???? GetLastError() ?? ??? ERROR_IO_PENDING ?? ??? ??, ???? ???? ?? ???? ??? ??? ????????? ????? ?? ??? ??? ???? ?? ????? ???? ???

?? ?????? ?? ????? i/O ???????? ????? synchronously ???? ?? ?????????? ???????? ?? ??? coded ???:

???????

?????????? ???????? ???? ?? ??? ?? obstruction, NTFS ??????? ??? ????? ?????? ??????? ????? ???? ???????? ??????? ?? ????? asynchronously; ???? ????? ?? ??? ??????? ??? ???? ??? ????????? ??? ?? COMPRESS ?? PKZIP ?? ???? ?????????? ?? ??? ??????? ?????? ?? ??? ???? ???? ?????

NTFS ???????????

?????? ?? ???? ???? ??, ????? ??????????? ???? ????????? ???? ?? ??? ?????????? i/O ??? ?????? ???? ?? ??? ?????? ???????? ??? ??????? ????????? ?? ??? ???, ?? i/O ???????? ?????????? ???? ??????

???? ???? ?? extending

???? ???? ???? i/O ???????? synchronously ????? ?? ??? ????? ???????? ??? Windows NT, ?? ??? ?? ??? ???? ????? ?? ????? ?? ?? ???? ????? ?? ??? ???????? ????????? ???? ??????

???:: ????????? ??? ???? ???? ???????? ???? ???????? ?????????? SetFileValidData ?????? ?? ????? ????, ?? ???? ??? ?? WriteFile ???? ?? ????? ?? ????? ???? ????? ?? ??? ???

SetFileValidData (?? Windows XP ?? ??? ?? ????????? ?? ?????? ??) ?? ????? ??, ????????? ?? ???? ??? ?????? ??????? ??????? ?????-?????? ?????? ?? ??? ???? ???????? penalty incurring ?????

??????? NTFS ????? ?????? ???? ?????-?? ????? ???? ????? (VDL) SetFileValidData, ?? ?????? ?????? ????????? ?? ?? ???? ??? ?? ??????? ???? ???????? ???? ???? ????? ?? ???? ?? ????? ????????? ???? ??????? ?? occupied ???? ??? ?????, SetFileValidData ?????? ???? ?? ??? SeManageVolumePrivilege ????? (???????? ??? ??, ?? ?? ???? ?? ????? ???? ??? ??????????)? ?? ISVs ????????????? ????? ???? ???????? ?? ?????? ?? ????? ???? ?? ???? ??? Microsoft ??????? ???? ???

???

(?????, ????? ?? ????) i/O ??????? ??????? ?? ??? ????? ??? ???, ???? "?????" ?? i/O ?????? ????? ?? ???? ???, ??? ???????? ????? ?? ????? ?? ReadFile ?? WriteFile ?????? TRUE ???? ?????? ??? ??? ??, ??? ?? ???????? ?? ???????? ?????? ?????????? ??? ????? ?????? ?? ??? ??????????, ?? i/O ?????? ?? ???? ??? ???? ?? ?? ???? "?????" ?? ??? ?????? ??? ???? ???

??? ??? ???? ???? ??

??? ????? ????? ?? ???? ?? ??????? ???, ???????, ??? ??? ??? ???? ???? ??? Windows NT ??? ????? ?????? internally ?? ????? ?? ???? ??? Windows NT ??? ?????? ??????? ??? ?????????? ????? ?????? ??????? ??? ??????? ?????? ????? ???? ??? ????? ?????? ?? ???????? ???? ?? ??? ?????? ???? ?????? ??? ??????? ?? ???? ??? ???????, ?????? ?? ???? ???? ??? ????? ??, ?????? ??? ????? ??? ?? ????? ?????????? ????? ??? ?? ??????? ??? ?????? ???? ???, ?? ????? ?????? ??????? ????? ?? ?? ???? ????? ????? ???? ???? ????? ??? ?? ?? ????? ??? ????? ????? ?? ?????? ?????? ????? ???? ?????? ???????? ??? ?? ????? ????? ?? ??? ?? ??? ???? ReadFile ??? ???? ?? ??? ?? ???? ????????? ?? ??? ???

?? ????????? ?? ?????? ?? ???, ??? ???? ?????? ?? ??? ??? ????? ????? ????? ?? ??? ?? ??????? ???? (??? ??? ?????? 16 MB), ????? ????? ??? ?? ??? ?????? ???? ?????????? ?? ????? ??????? ?? ??? ?? ????? ???? ??? ?? ???? ???? ??? ??? ???? ?? ?? ???? ?? ??? i/O ???????? ?? ?????, ??? ??????? ?? ?????? ??????? saturated ?? ??? ?? ???? ???????? ????????? ??? ????

??? ??????? ?? ??????? ?? ???? ??? ?? ?? influenced ?? ???? ?? ???? ????? ?? ????? sequentially ?? ?????????? ?? ?????? ??? ??? ?? ??? ??? ???? ???? ?? sequentially ??????? ?? ?????? FILE_FLAG_SEQUENTIAL_SCAN ???? CreateFile ??? ??? ??? ?? ?? ?????? ?? ????? ?? ??? ????????? ???? ?????? ???????, ??? ?? ???? ????? ??????? ??? ??????? ?? ????? ??, ????? FILE_FLAG_RANDOM_ACCESS ???? CreateFile ??? ???? ??????? ?? ????? ????? ?? ??? ????????? ???? ?? ??? ??? ??????? instruct ???? ?? ????

??? ?? ????? ????

FILE_FLAG_NO_BUFFERING ???? ?? ?? ??????? ?????????? ???????? ?? ??? ????? ?????? ?? ??????? ?????? ???? ?? i/O ???????? ?????????? ?????? ??? ??? ?? ?? ?????? ?? ?? ???? ????? ????? ??? ?? instructs ? ?? ??? ??? ??????? ?? ????? ???? ?? ??? ????? ?????? ???

???????:: ?? ???? ?? ????? ???? ?? ??? ??? ???????? ?? ???? ???? ?????? ?? ???? ?????? ??? ?????? ?? ??? ???? ???? ?? ??? ??? ???? ?????? ?????? ??? ?? ????? ?? ???? ??? ?? ?????? ?? ???? ??? ???? ??????? ?? ??? CreateFile ?????? ?? ??? ???????? ??????

????? ???

????? ????? Microsoft ??????? ?????? ?? ??????? ?? ??? ?????? ??::
Asynczip.exe (http://download.microsoft.com/download/platformsdk/sample/3/NT4/EN-US/ASYNCZIP.EXE)
Microsoft ?????? ??????? ?? ???? ??????? ???? ?? ???? ??? ???? ????? ?? ???, ????? ???? ?????? ?? ????? ?? ???? ?? Microsoft ???????? ??? ?????::
119591  (http://support.microsoft.com/kb/119591/EN-US/ ) ?????? ?????? ?? Microsoft ?????? ??????? ???? ??????? ????
Microsoft ????? ?? ??? ?? ????? ?? ????? ?? ??? Microsoft ?? ?? ?????? ?? ?????? ???? ??????? ?????-??? ?????????? ?? ????? ???? ?? ????? ????? ?? ?? ??.. ????? ?? ?? ???????-??????????? ????? ?? ???????? ???? ??? ?? ?? ????? ??? ???? ?? ??????? ???????? ?? ????? ??? ??? ???? ??..?? ???? ?? ??? ?????? ????? ??? ?? ????????? ???? ?? ?? ???? ?? discussed ?????? ?? ????? ????? ??? Windows NT ?? ???? ????? ????????? ?? ??? ??? ????? ???? ??? ????? ???? ?????? ????? ???? ??, ???? ??????? ????????:
   Asynchio
   Usage: asynchio [options]

   Options:
      /fFilePattern  Files to use for I/O.
      /s    Specifies synchronous operation.
      /n    Specifies that no buffering should be used
      /r    Use FILE_FLAG_RANDOM_ACCESS
      /l    Use FILE_FLAG_SEQUENTIAL_SCAN
      /o###    Issue ### operations
      /e    First read entire file, then issue smaller reads
      /?    Display this usage message.
				
??????: asynchio /f*.bmp /n
?? ????????? ?? ??????? ????????, buffered ?????????? ???????? ?? ??? ??? ???????? ??? ??, 500 i/O ???????? ?????? ????

???????? ?????? ??????? ??????

????? ?? ????? ??? ?? ??? ??????? ?? ?????? ???? ???????? ?? magnitude ???? ???? ?????????? ?? ?? ???????? ?? ?????? ??, ????? ???????? ?? ?? ????? ?? ????? ?? ????? ??? ??????? ?????? ?? ???????? ?? ???? illuminates.

?? ????? ?? ???? ?????? ????? ?? ??? ??????? ?? ???? ???:
  • ??????? 1
    Asynchronous, unbuffered I/O:  asynchio /f*.dat /n
    
       Operations completed out of the order in which they were requested.
       500 requests queued in 0.224264 seconds.
       500 requests completed in 4.982481 seconds.
    						
    ????????? ???? ?? ?? ??????? ?? ?? ???? ???????? ????????? 500 i/O ???????? ?? ??????? ?? ???? ???? ??? ?? ?? ???? ????? ???? ??? ?? ???? ???????? ?? ????? ???? ?? ??? ??? ?? ?? ???? ???
  • ??????? 2
    Synchronous, unbuffered I/O: asynchio /f*.dat /s /n
    
       Operations completed in the order issued.
       500 requests queued and completed in 4.495806 seconds.
    						
    ?? ???? ?? ????????? ???? ?? ?? ?? ????????? ???? 4.495880 ????? whereas ??????? 1 ???? ?? ?????? ????? ???? ?? ??? ???? 0.224264 ????? ???? ??????????? ????? ???? ?? ??? ReadFile ?? ??? ????? ??????? 2 ??? ??, ???? ?? ????????? ????? ???? ?? ??? ????????? ?? ??? "????????" ??? ???? ???
  • ??????? 3
    Asynchronous, buffered I/O: asynchio /f*.dat
    
       Operations completed in the order issued.
       500 requests issued and completed in 0.251670 seconds.
    						
    ?? ??????? ????????? ???? ?? ?? ??? ?? ????????? ??????? ????? ??? reads ???? ??? ?? ?? ?? 0.251670 ????? ??? ????? ??? ????? ?????? ???, ?????????? ?????? ??? ?? ????? synchronously. ????????? ???? ?? ?? ??????? ?? ?? ??? ??????? ?? ???? ??????????? ?? ??? ??? ???? ???
  • ??????? 4
    Synchronous, buffered I/O: asynchio /f*.dat /s
    
       Operations completed in the order issued.
       500 requests and completed in 0.217011 seconds.
    						
    ?? ??????? ????????? ???? ?? ?? ?? ?? ?????? ??? ??????? 3 ?? ??? ???? ????? ??? ?? ??? ?? ????????? reads ????? little ?? ???? ?????????? reads ?? ??? ?? ??? ????????? ???? ?? ?? ??????? ?? ?? ??? ??????? ?? ???? ??????????? ?? ??? ??? ???? ???

CONCLUSION

?? ??? ?? ???? ????? ?? ??????? ?? ??? ??????, ????, ?? ???? ????????? ?? ????????? ???? ?? ?? ???????? ?? ?????? ?? ?????? ???? ?? ?? ?? ???? ???

??????? ????? ????? CreateFile ???? ?? ??? ??? ????? ????? ????????? ??? ????, ????????? ?? ??? ?? ?? ???????? ???

???:: ?? ??????? ??? ???????? ?????????? ??????? ?? ??? ??? ?? ??????? ????? ?????? ??????? predictive ?????????? ???-???? ?? ??? ?? ?????????? lazy ???? ?? ???? ?? ??????? ???? ??? ?????? ?? ???? ?? ????????? [ASCII 146] s i/O ??????????, ?? ??? vast majority ?????? ??????????? ?? ??? ideal ???????

???, ?? ????? ???, ???? ????????? ???? ???? ??, ?? ?? ??? profiling ?? ??????? ????, ?? ???? ??? ???? illustrated ??????? ???? ?? ??? ???? ????????? ???? ?? ??? ?????????? ????????? ?? ???? ???? ????? ??? profiling ReadFile ?? WriteFile ?????? ??? ???? ?? ???????? ?????? ???? ?? ?? ???? ???? ???? ???????? i/O ???????? ????? ???? ?? ??? ?? ??? ?? ??? ?? ????? ????? ??? ?????? ??? i/O ???? ??? majority ??? ???? ?? ??, ?? ???? i/O ?? ???? ?? ??? ????? synchronously. ???????, ??? ??? ???? ????????? i/O ???????? ?? ?????????? ???? ???? ???? ???, ???? ???? ?? ??? i/O ???????? ?? ??? ???? ???????? asynchronously ???? ?? ??? ?? ?? ??? ?? ????? ????? ???? ?? ???? ??? ???????? ????? ??? ?? ???? ?? ??? ???? ?????? profiling QueryPerformanceCounter ?????? ?? ????? ???? ???

???????? ????????? ?????? ???? ???? ????????? ?? ????? ????? ?? ??? ????????? ??? ?? ???? ??? ??????????? ?????? ?? ??? ???????? ?? ??? ??? ???????? ??? ??????? ?? ??????????? ????? ????? ????? ????? ?? ??????? ????? ?????????? ?? ??? ??????????? ?????? ???????? ????? ?????? ?? ??????????? ?? ????? ??????

???????? ????????? ??? ?????? ?? ?????????? ???, ?????????? ?????? ?? ?? DiskPerf ????? ??? ?? ?????? ???? ????? ?????? ?? ??????????? ?? ???? ??????? ???? ?? ??? ?????? ?? ??? ???? ???? diskperf -y ???? ????? ???? ?????? ??? ???? ???? ?????, ?? ??? ???? ?????? ??????? ???? ?? ??? ?????? ???????? ???? ?????? ???

??????

?? ?????????? ?? ??????????? ??????? ?? ???? ??? ???? ??????? ?? ??? Windows NT ?????? ??? ?????????? ??? "Optimizing Windows NT" ??? ??????
SQL ????? ?? ??? ?????? ?????? ?? ?????? ???? ?? ??? ? ????? ?????? ?? ????? ???? ?? ??? ????????? ? ?? ??? ??? Microsoft SQL Server Always-on ??????? ?????? ??????? ????????? ?? ???? ??? ??? FoSQL Server ??????? ????? ?? ????? ?? ?????? ?????????? ?? ???? ??? ???? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
967576  (http://support.microsoft.com/kb/967576/ ) Microsoft SQL Server ??????? ????? ?????/?????? ??????????

???? ???? ???? ??:
  • Microsoft Win32 Application Programming Interface
  • Microsoft SQL Server 2008 Developer
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 Express
  • Microsoft SQL Server 2008 Standard
??????: 
kbapi kbfileio kbinfo kbkernbase kbmt KB156932 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:156932  (http://support.microsoft.com/kb/156932/en-us/ )