Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
10 KiB

  1. README.txt
  2. Author: Murali R. Krishnan (MuraliK)
  3. Created: Jan 6, 1997
  4. Revisions:
  5. Date By Comments
  6. ----------------- -------- -------------------------------------------
  7. Summary :
  8. This file describes the files in the directory svcs\infocomm\atq
  9. and details related to ISATQ - Internet Services Async Thread Queue module
  10. File Owner Description
  11. README.txt MuraliK This file.
  12. abw.hxx MuraliK Bandwidth throttler declarations
  13. abw.cxx MuraliK Bandwidth throttler for ATQ
  14. acache.cxx MuraliK Alloc Cache module
  15. atqbmon.cxx MCourage Listen backlog monitor
  16. atqbmon.hxx MCourage Listen backlog monitor header
  17. atqcport.cxx JohnsonA Fake Completion port for Win95
  18. atqcport.hxx JohnsonA Fake Completion port for Win95 header
  19. atqendp.cxx MuraliK Atq Endpoint manager
  20. atqmain.cxx MuraliK Exposed ATQ entrypoints
  21. atqprocs.hxx MuraliK Internal Function Prototypes
  22. atqsupp.cxx MuraliK Atq Support Functions - timeout, thread pool, etc.
  23. atqtypes.hxx MuraliK Atq Internal Types
  24. atqxmit.cxx JohnsonA Internal routines for TransmitFile()
  25. auxctrs.hxx MuraliK Auxiliar counters - for internal analysis
  26. dbgutil.h MuraliK Debug support definitions
  27. dllmain.cxx MuraliK Dll Entry points
  28. isatq.def MuraliK .def file
  29. isatq.hxx MuraliK pre-compiled header file
  30. isatq.rc MuraliK Resource file
  31. sched.cxx MuraliK IIS Scheduler - internal thread pool for scheduling
  32. sched.hxx MuraliK Scheduler data structures
  33. timeout.cxx MuraliK ATQ Contexts Timeout Logic
  34. timer.cxx MuraliK Time measurement support code
  35. xmitnt.cxx JohnsonA obsolete file - replaced by atqxmit.cxx
  36. ----------------------------------------------------------------------
  37. Implementation Details
  38. Contents:
  39. ATQ based Bandwidth Throttle
  40. Author: MuraliK
  41. Date: 25-May-1995
  42. Goal:
  43. Given a specified bandwidth which should be used as threshold,
  44. the ATQ module shall throttle traffic, gracefully. Minimum CPU impact
  45. should be seen; Minor variations above specified threshold is
  46. allowed. Performance in the fast cause (no throttle) should be high
  47. and involve less stuff in the critical path.
  48. Given:
  49. M -- an administrator specified bandwidth which should not be
  50. exceeded in most cases. (assume to be specified through a special API
  51. interface added to ATQ module)
  52. Solution:
  53. Various solutions are possible based on measurements and metrics
  54. chosen. Whenever two possible solutions are possible, we pick the
  55. simplest one to avoid complexity and performance impact. (Remember to
  56. K.I.S.S.)
  57. Sub Problems:
  58. 1) Determination of Exisiting Usage:
  59. At real time determining existing usage exactly is computationally
  60. intensive. We resort to approximate measures whenever possible.
  61. Idea is: Estimated Bandwidth = (TotalBytesSent / PeriodOfObservation).
  62. solution a)
  63. Use a separate thread for sampling and calculating the
  64. bandwidth. Whenever an IO operation completes (we return from
  65. GetQueuedCompletionStatus()), increment the TotalBytesSent for the
  66. period under consideration. The sampling thread wakes up at regular
  67. intervals and caclulates the bandwidth effective at that time. The solution
  68. also uses histogramming to smooth out sudden variations in the bandwidth.
  69. This solution is:
  70. + good, since it limits complexity in calculating bandwidth
  71. - ignores completion of IO simultaneously => sudden spikes are possible.
  72. - ignores the duration took for actual IO to complete (results could be
  73. misleading)
  74. - requires separate sampling thread for bandwidth calculation.
  75. solution b)
  76. This solution uses a running approximation of time taken for
  77. completing an i/o of standard size viz., 1 KB transfer. Initially we start
  78. with an approximation of 0 Bytes sent/second (reasonable, since we just
  79. started). When an IO completes, the time taken for transfer then is
  80. calculated from the count of bytes sent and time required from inception to
  81. end of IO. Now we do a simple average of existing approximation and the
  82. newly caculated time. This gives the next approximation for bandwidth/time
  83. taken. Successively the calculations refine the effective usage measurement
  84. made. (However, we must note, by so simplifying, we offset ourselves from
  85. worrying about the concurrency in IO processing.) In case of concurrent
  86. transfers time taken for data transfer is larger than the actual time only
  87. for the particular transfer. Hence, the solution makes conservative
  88. estimates based on this measured value.
  89. + no separate thread for sampling
  90. + simple interface & function to calculate bandwidth.
  91. - avoids unusaual spikes seen in above solution.
  92. 2) Determination of Action to be performed:
  93. The allowed operations in ATQ module include Read, Write and
  94. TransmitFile. When a new operation is submitted, we need to evaluate if it
  95. is safe(allow), marginally safe(block) or unsafe(reject) to perform the
  96. operation. Evaluation of "safety"ness is tricky and involves knowledge
  97. about the operations, buffers used, CPU overhead for the operation setup,
  98. and estimated and specified bandwidths.
  99. Assume M and B as specified and estimated bandwidths respectively. Let
  100. R,W, and T stand for the operations Read, Write and TransmitFile. In
  101. addition assume that s and b are used as suffixes for small and big
  102. transfers. Definition of small and big are arbitrary and should be fixed
  103. empirically. Please refer the following table for actions to be performed.
  104. Action Table:
  105. ------------------------------------------------------------------------------
  106. \ Action |
  107. Bandwidth\ to be | Allow Block Reject
  108. comparison\ Done |
  109. ------------------------------------------------------------------------------
  110. M > B R,W,T - -
  111. M ~= B W, T R -
  112. (approx. equal) (reduces future traffic)
  113. M < B Ws, Ts Wb, Tb R
  114. (reject on LongQueue)
  115. ------------------------------------------------------------------------------
  116. Rationale:
  117. case M > B: In this case, the services are not yet hitting the limits
  118. specified, so it is acceptable to allow all the operations to occur without
  119. any blockage.
  120. case M ~= B: (i.e. -delta <= |(M - B)| <= +delta
  121. [Note: We use approximation, since exact equal is costly to calculate.]
  122. At this juncture, the N/w usage is at the brink of specified bandwidth. It
  123. is good to take some steps to reduce future traffic. Servers operate on
  124. serve-a-request basis -- they receive requests from clients and act upon
  125. them. It is hence worthwhile to limit the number of requests getting
  126. submitted to the active queue banging on the network. By delaying the Read,
  127. processing of requests are delayed artificially, leading to delayed load on
  128. the network. By the time delayed reads proceed, hopefully the network is
  129. eased up and hence server will stabilise. As far as write and transmit
  130. goes, certain amount of CPU processing is done and it is worthwhile to
  131. perform them, rather than delaying and queueing, wasting CPU usage.
  132. Another possibility is: Do Nothing. In most cases, the load may be coming
  133. down, in which case the bandwidth utilized will naturally get low. To the
  134. contrary allowing reads to proceed may result in resulting Write and
  135. Transmit loads. Due to this potential danger, we dont adopt this solution.
  136. case M < B:
  137. The bandwidth utilization has exceeded the specified limit. This is an
  138. important case that deserves regulation. Heavy gains are achieved by
  139. adopting reduced reads and delaying Wb and Tb. Better yet, reads can be
  140. rejected indicating that the server is busy or network is busy. In most
  141. cases when the server goes for a read operation, it is at the starting
  142. point of processing any future request from client (exception is: FTP
  143. server doing control reads, regularly.) Hence, it is no harm rejecting the
  144. read request entirely. In addition, blocking Wb and Tb delays their impact
  145. on the bandwidth, and brings down the bandwidth utilization faster than
  146. possible only by rejecting Reads. We dont want to reject Wb or Tb, simply
  147. because the amount of CPU work done for the same may be too high. By
  148. blocking them, most of the CPU work does not go waste.
  149. Implementation:
  150. To be continued later.
  151. The action table is simplified as shown below to keep the implementation
  152. simpler.
  153. Action Table:
  154. ------------------------------------------------------------------------------
  155. \ Action |
  156. Bandwidth\ to be | Allow Block Reject
  157. comparison\ Done |
  158. ------------------------------------------------------------------------------
  159. M > B R,W,T - -
  160. M ~= B W, T R -
  161. (approx. equal) (reduces future traffic)
  162. M < B W, T R
  163. ------------------------------------------------------------------------------
  164. Status and Entry point Modifications:
  165. We keep track of three global variables, one each for each of the
  166. operations: Read, Write and XmitFile. The values of these variables
  167. indicate if the operation is allowed, blocked or rejected. The entry points
  168. AtqReadFile(), AtqWriteFile() and AtqXmitFile() are modified to check the
  169. status and do appropriate action. If the operation is allowed, then
  170. operation proceeds normally. If the operation is blocked, then we store
  171. the context in a blocked list. The parameters of the entry points, which
  172. are required for restarting the operation are also stored along with
  173. context. The operation is rejected, if the status indicates rejection. All
  174. these three global variables are read, without any synchronization
  175. primitives around them. This will potentially lead to minor
  176. inconsistencies, which is acceptable. However, performance is improved
  177. since there is no syncronization primitive that needs to be accessed.( This
  178. assertion however is dependent upon SMP implementations and needs to be
  179. verified. It is deferred for current implementation.)