index.rst 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. .. _control_flow:
  2. Control flow module
  3. ===================
  4. The ``control-flow`` module for GeoServer allows the administrator to control the amount of concurrent requests actually executing inside the server,
  5. as well as giving an opportunity to slow down users making too many requests.
  6. This kind of control is useful for a number of reasons:
  7. * *Performance*: tests show that, with local data sources, the maximum throughput in `GetMap` requests is achieved when allowing at most 2 times the number of CPU cores requests to run in parallel.
  8. * *Resource control*: requests such as `GetMap` can use a significant amount of memory. The :ref:`WMS request limits<wms_configuration_limits>` allow to control the amount of memory used per request, but an ``OutOfMemoryError`` is still possible if too many requests run in parallel. By controlling also the amount of requests executing it's possible to limit the total amount of memory used below the memory that was actually given to the Java Virtual Machine.
  9. * *Fairness*: a single user should not be able to overwhelm the server with a lot of requests, leaving other users with tiny slices of the overall processing power.
  10. The control flow method does not normally reject requests, it just queues up those in excess and executes them late. However, it's possible to configure the module to reject requests that have been waited in queue for too long.
  11. Installation
  12. ------------
  13. #. Visit the :website:`website download <download>` page, locate your release, and download: :download_extension:`control-flow`
  14. .. warning:: Ensure to match plugin (example |release| above) version to the version of the GeoServer instance.
  15. #. Extract the files in this archive to the :file:`WEB-INF/lib` directory of your GeoServer installation.
  16. #. Restart GeoServer
  17. Rule syntax reference
  18. ---------------------
  19. The current implementation of the control flow module reads its rules from a ``controlflow.properties`` property file located in the :ref:`datadir`.
  20. Total OWS request count
  21. .......................
  22. The global number of OWS requests executing in parallel can be specified with::
  23. ows.global=<count>
  24. Every request in excess will be queued and executed when other requests complete leaving some free execution slot.
  25. Per request control
  26. ...................
  27. A per request type control can be demanded using the following syntax::
  28. ows.<service>[.<request>[.<outputFormat>]]=<count>
  29. Where:
  30. * ``<service>`` is the OWS service in question (at the time of writing can be ``wms``, ``wfs``, ``wcs``)
  31. * ``<request>``, optional, is the request type. For example, for the ``wms`` service it can be ``GetMap``, ``GetFeatureInfo``, ``DescribeLayer``, ``GetLegendGraphics``, ``GetCapabilities``
  32. * ``<outputFormat>``, optional, is the output format of the request. For example, for the ``wms`` ``GetMap`` request it could be ``image/png``, ``image/gif`` and so on
  33. A few examples::
  34. # don't allow more than 16 WCS requests in parallel
  35. ows.wcs=16
  36. # don't allow more than 8 GetMap requests in parallel
  37. ows.wms.getmap=8
  38. # don't allow more than 2 WFS GetFeature requests with Excel output format
  39. ows.wfs.getfeature.application/msexcel=2
  40. Request priority support
  41. ........................
  42. Requests controlled by "ows.*" controllers above can be also executed in priority order, in case there are too many
  43. the request will block and wait, and will we awoken in priority order (highest to lowest).
  44. Currently the only way to specific a priority for a request is to add it to a request HTTP header::
  45. ows.priority.http=<headerName>,<defaultPriority>
  46. The header "headerName" will contain a number defining the priority for the request, the default priority is used
  47. as a fallback if/when the header is not found.
  48. Using a header implies some other system is involved in the priority management. This is particularly good when using
  49. a load balancer, as the requests priorities need to be evenly split across cluster elements, control-flow only
  50. has visibility of a single instance. As an example, the priority will be de facto ignored at the cluster level
  51. if there are two nodes, and for whatever chance or design, the high priority requests end up converging on the same cluster node.
  52. Per user concurrency control
  53. ............................
  54. There are two mechanisms to identify user requests. The first one is cookie based, so it will work fine for browsers but not as much for other kinds of clients. The second one is ip based, which works for any type of client but that can limit all the users sitting behind the same router
  55. This avoids a single user (as identified by a cookie) to make too many requests in parallel::
  56. user=<count>
  57. Where ``<count>`` is the maximum number of requests a single user can execute in parallel.
  58. The following avoids a single ip address from making too many requests in parallel::
  59. ip=<count>
  60. Where ``<count>`` is the maximum number of requests a single ip address can execute in parallel.
  61. It is also possible to make this a bit more specific and throttle a single ip address instead by using the following::
  62. ip.<ip_addr>=<count>
  63. Where ``<count>`` is the maximum number of requests the ip specified in ``<ip_addr>`` will execute in parallel.
  64. To reject requests from a list of ip addresses::
  65. ip.blacklist=<ip_addr1>,<ip_addr2>,...
  66. Per user rate control
  67. .....................
  68. The rate control rules allow to setup the maximum number of requests per unit of time, based either
  69. on a cookie or IP address. These rules look as follows (see "Per user concurrency control" for the meaning of "user" and "ip")::
  70. user.ows[.<service>[.<request>[.<outputFormat>]]]=<requests>/<unit>[;<delay>s]
  71. ip.ows[.<service>[.<request>[.<outputFormat>]]]=<requests>/<unit>[;<delay>s]
  72. Where:
  73. * ``<service>`` is the OWS service in question (at the time of writing can be ``wms``, ``wfs``, ``wcs``)
  74. * ``<request>``, optional, is the request type. For example, for the ``wms`` service it can be ``GetMap``, ``GetFeatureInfo``, ``DescribeLayer``, ``GetLegendGraphics``, ``GetCapabilities``
  75. * ``<outputFormat>``, optional, is the output format of the request. For example, for the ``wms`` ``GetMap`` request it could be ``image/png``, ``image/gif`` and so on
  76. * ``<requests>`` is the number of requests in the unit of time
  77. * ``<unit>`` is the unit of time, can be "s", "m", "h", "d" (second, minute, hour and day respectively).
  78. * ``<delay>`` is an optional the delay applied to the requests that exceed the maximum number of requests in the current time slot. If not specified, once the limit is exceeded a immediate failure response with HTTP code 429 ("Too many requests") will be sent back to the caller.
  79. The following rule will allow 1000 WPS Execute requests a day, and delay each one in excess by 30 seconds::
  80. user.ows.wps.execute=1000/d;30s
  81. The following rule will instead allow up to 30 GetMap requests a second, but will immediately fail any request exceeding the cap::
  82. user.ows.wms.getmap=30/s
  83. In both cases headers informing the user of the request rate control will be added to the HTTP response. For example::
  84. X-Rate-Limit-Context: Any OGC request
  85. X-Rate-Limit-Limit: 10
  86. X-Rate-Limit-Remaining: 9
  87. X-Rate-Limit-Reset: 1103919616
  88. X-Rate-Limit-Action: Delay excess requests 1000ms
  89. In case several rate control rules apply to a single request, a batch of headers will be added to the
  90. response for each of them, it is thus advised to avoid adding too many of these rules in parallel
  91. Where:
  92. * ``X-Rate-Limit-Context`` is the type of request being subject to control
  93. * ``X-Rate-Limit-Limit`` is the total amount of requests allowed in the control interval
  94. * ``X-Rate-Limit-Remaining`` is the number of remaining requests allowed before the rate control kicks in
  95. * ``X-Rate-Limit-Reset`` is the Unix epoch at which the new control interval will begin
  96. * ``X-Rate-Limit-Action`` specifies what action is taken on requests exceeding the rate control
  97. Timeout
  98. .......
  99. A request timeout is specified with the following syntax::
  100. timeout=<seconds>
  101. where ``<seconds>`` is the number of seconds a request can stay queued waiting for execution. If the request does not enter execution before the timeout expires it will be rejected.
  102. Throttling tile requests (WMS-C, TMS, WMTS)
  103. -------------------------------------------
  104. GeoWebCache contributes three cached tiles services to GeoServer: WMS-C, TMS, and WMTS. It is also possible to use the
  105. Control flow module to throttle them, by adding the following rule to the configuration file::
  106. ows.gwc=<count>
  107. Where ``<count>`` is the maximum number of concurrent tile requests that will be delivered by GeoWebCache at any given time.
  108. Note also that tile request are sensitive to the other rules (user based, ip based, timeout, etc).
  109. A complete example
  110. ------------------
  111. Assuming the server we want to protect has 4 cores a sample configuration could be:
  112. .. literalinclude:: controlflow.properties
  113. :language: properties