Debian Codegraph @

doc/sources/admin/performances.rst

raw
1 Performances
2 ============
3
4 LemonLDAP::NG is designed for high performance, both in throughput and
5 response time. Indeed, it can use Apache2 threads capabilities **but**
6 since Apache version 2.4, mpm_worker seems to break mod_perl. So to
7 increase performances, prefer using Nginx.
8
9 Built-in
10 --------
11
12 Cache system
13 ~~~~~~~~~~~~
14
15 LLNG uses different cache systems to avoid querying to many the
16 databases:
17
18 ============= ======================== ========== ============================== ==================== ==
19 \ Lifetime in memory Lifetime in Local-Cache (file) DB
20 ============= ======================== ========== ============================== ==================== ==
21 \ Parameter Default Parameter Default
22 Configuration ``checkTime`` [1]_ 1 second Until "reload" order ✔
23 Session ``handlerInternalCache`` 15 seconds ``default_expires_in`` [2]_ 10 minutes ✔
24 ============= ======================== ========== ============================== ==================== ==
25
26 .. [1] See also :doc:`Event management <eventsmanagement>`
27
28 .. [2] Manager >> General parameters >> Sessions >> Sessions storage >> Cache module options
29
30
31 .. note::
32
33 Configuration and sessions are first looked up in-memory, then in
34 the cache file, and then in their backing store. This means that after a
35 configuration reload (using Manager), you have to wait for
36 ``checkTime`` before you can see your changes, or wait for configuration
37 cache expiration in ``checkTime`` is disabled.
38
39 Global performance
40 ------------------
41
42 By default, Linux does not use DNS cache and LemonLDAP::NG portal
43 request DNS for each connexions on LDAP or DB. Under heavy loads, that
44 can generated hundred of DNS queries and many errors on LDAP connexions
45 (timed out) from IO::Socket.
46
47 To bypass this, you can:
48
49 - Use IP in configuration to avoid DNS resolution
50 - Install a DNS cache like nscd, dnsmasq or unbound
51
52 Cron optimization (or systemd timers)
53 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54
55 LLNG installs its cron files without knowing how many servers are
56 installed. You should optimize this to launch:
57
58 - purgeCentralCache: only 1 time every 10 minutes for the whole system
59 (or more)
60 - purgeLocalCache: ~ 1 time per hour on each server
61
62 .. _performances-handler-performance:
63
64 Handler performance
65 -------------------
66
67 For Nginx, you can use another auth server instead of
68 llng-fastcgi-server. See: :doc:`Advanced PSGI usage<psgi>`.
69
70 To increase handler performance, you can disable "Sessions activity
71 timeout" to prevent it from writing to the session database.
72
73 Handlers check rights and calculate headers for each HTTP hit. So to
74 improve performances, avoid too complex rules by using macros, groups or
75 local macros.
76
77 Local macros
78 ~~~~~~~~~~~~
79
80 Macros and groups are stored in session database. Local macros is a
81 special feature of handler that permit one to have macros useable localy
82 only. Those macros are calculated only at the first usage and stored in
83 the local session cache (only for this server) and only if the user
84 access to the related applications. This avoid to have to many data stored.
85
86 .. code-block:: perl
87
88 # rule
89 admin -> $admin ||= ($uid eq 'foo' or $uid eq 'bar')
90 # header
91 Display-Name -> $displayName ||= $givenName." ".$surName
92
93
94 .. tip::
95
96 Note that this feature is interesting only for the
97 Lemonldap::NG systems protecting a high number of applications
98
99 Portal performances
100 -------------------
101
102 General performances
103 ~~~~~~~~~~~~~~~~~~~~
104
105 The portal is the biggest component of Lemonldap::NG. Since version 2.0,
106 portal runs under FastCGI and has been rewritten using plugins, so
107 performance is increased in comparison to earlier versions. You just
108 have to disable unused plugins:
109
110 - disable unused issuer modules
111 - disable notifications if not used
112 - ...
113
114 By default it uses local storage to store its tokens. If you have more
115 than 1 portal and if your load-balancer doesn't keep state, you have to
116 disable this to use the global session storage *(General parameters »
117 portal Parameters » Advanced Parameters » Forms)*. Note that this will
118 decrease performances.
119
120
121 .. tip::
122
123 In production environment for network performance, prefer
124 using minified versions of javascript and css libs: use
125 ``make install PROD=yes``. This is done by default in RPM/DEB
126 packages.
127
128
129 .. _performances-apachesession-performances:
130
131 Apache::Session performances
132 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133
134 Lemonldap::NG handlers use a local cache to store sessions (for 10
135 minutes). So Apache::Session module is not a problem for handlers. But
136 it can be a bottleneck for the portal:
137
138 #. When you use the multiple sessions restriction parameters, sessions
139 are parsed for each authentication unless you use an
140 `Apache::Session::Browseable <https://metacpan.org/module/Apache::Session::Browseable>`__
141 module.
142 #. Since MySQL does not have always transaction feature,
143 Apache::Session::MySQL has been designed to
144 use MySQL locks. Since MySQL performances are very bad using this, if
145 you want to store sessions in a MySQL database, prefer one of the
146 following
147
148
149 .. tip::
150
151 Since 1.9.6, LLNG portal and handler check if session is valid
152 at each access, so purgeCentralCache cron no longer needs to be launched
153 every 10 minutes: one or two times per day is enough.
154
155 .. _replace-mysql-by-apachesessionflex:
156
157 Replace MySQL by Apache::Session::Flex
158 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159
160 In "Apache::Session module" field, set
161 "`Apache::Session::Flex <https://metacpan.org/module/Apache::Session::Flex>`"
162 and use the following parameters:
163
164 ::
165
166 Store -> MySQL
167 Lock -> Null
168 Generate -> MD5
169 Serialize -> Storable
170 DataSource -> dbi:mysql:sessions;host=...
171 UserName -> ...
172 Password -> ...
173
174
175 .. tip::
176
177 Since version 1.90 of Apache::Session, you can use
178 Apache::Session::MySQL::NoLock instead
179
180 .. _use-apachesessionbrowseable:
181
182 Use Apache::Session::Browseable
183 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
184
185 `Apache::Session::Browseable <https://metacpan.org/module/Apache::Session::Browseable>`__
186 is a wrapper for other Apache::Session modules that add the capability
187 to manage indexes. Prefer versions ≥ 1.2.5 for better performances in DB
188 cleaning. To use it (with PostgreSQL for example), choose
189 "Apachedoc:`Session::Browseable<session::browseable>`::Postgres" as
190 "Apache::Session module" and use the following parameters:
191
192 ::
193
194 DataSource -> dbi:Pg:database=sessions;host=...
195 UserName -> user
196 Password -> password
197 Index -> ipAddr uid
198
199 Note that
200 Apache::Session::Browseable::MySQL doesn't
201 use MySQL locks.
202
203 Look at :doc:`Browseable session backend<browseablesessionbackend>` to
204 known which index to choose.
205
206
207 .. attention::
208
209 Some Apache::Session module are not fully usable by
210 Lemonldap::NG such as Apache::Session::Memcached since these
211 modules do not offer capability to browse sessions. They does not allow
212 one to use sessions explorer neither manage one-off sessions.
213
214 .. _performance-test:
215
216 Performance test
217 ^^^^^^^^^^^^^^^^
218
219
220 .. tip::
221
222 A
223 `Apache::Session::Browseable::Redis <https://metacpan.org/module/Apache::Session::Browseable::Redis>`__
224 has been created, it is the fastest (except for session explorer,
225 defeated by Apache::Session::Browseable:: `DBI <https://metacpan.org/module/Apache::Session::Browseable>`__ / `LDAP <https://metacpan.org/module/Apache::Session::Browseable::LDAP>`__)
226
227 This test isn't an "only-backend" test but embedded some LLNG methods,
228 so real differences between engines are mitigate here.
229
230 ====================================================================== ============================ =================== ========== =================== ===================================== =================== =============
231 Backend Portal and handlers Session explorer and one-off sessions
232 --------------------------------------------------------------------------------------------------- -------------------------------------------------- -----------------------------------------------------------------------
233 Name Configuration Insert 1000 Search 1 Purge 500 Parse all Search by substring Search by UID
234 ====================================================================== ============================ =================== ========== =================== ===================================== =================== =============
235 Apache::Session::\ **Browseable::LDAP** mdb 159.66 0.0120 49.22 0.1110 0.0076 0.0050
236 Apache::Session::\ **MySQL** No lock 87.20 **0.0039** 23.14 0.0281 0.0252 0.0235
237 Apache::Session::\ **Browseable::MySQL** 91.79 **0.0039** **0.139** [3]_ 0.0272 **0.0036** **0.0026**
238 Apache::Session::\ **Browseable::MySQLJSON** 86.06 0.0145 \*\* 0.151*\* [4]_ **0.0104** 0.0137 0.0038
239 Apache::Session::\ **Postgres** 18.31 0.0095 13.40 0.0323 0.0277 0.0264
240 Apache::Session::\ **Postgres** Unlogged table 9.16 0.0095 7.91 0.0318 0.0270 0.0254
241 Apache::Session::\ **Browseable::Postgres** Unlogged table with indexes 9.24 0.0094 **0.103** [3]_ 0.0301 **0.0036** **0.0028**
242 Apache::Session::\ **Browseable::PgJSON** Unlogged table, json field 9.25 0.0091 **0.108** [3]_ 0.0247 **0.0035** **0.0029**
243 Apache::Session::\ **Browseable::PgJSON** Unlogged table, jsonb field 9.25 0.0091 **0.105** [3]_ **0.0126** **0.0034** **0.0029**
244 Apache::Session::\ **Browseable::PgHstore** Unlogged table, hstore field 9.62 0.0111 **0.105** [3]_ **0.0125** **0.0033** **0.0029**
245 Apache::Session::\ **Browseable::Redis** **2.36** **0.0033** 1.154 0.0643 0.1048 **0.0024**
246 ====================================================================== ============================ =================== ========== =================== ===================================== =================== =============
247
248 *The source of this test is available in sources: e2e-tests/sbperf.pl*
249
250 .. [3] "purge" test is done with Apache::Session::Browseable-1.2.5
251 and LLG-2.0. Earlier results are not so good.
252 .. [4] "purge" test is done with Apache::Session::Browseable-1.2.6
253 and LLG-2.0.
254
255 Analysis:
256
257 - LDAP servers are "write-once-read-many", so write performances are
258 very bad. Don't use this on heavy load
259 - MySQL/MariaDB is better to read than to write. Prefer PostgreSQL if
260 you use "Session activity timeout"
261 - Logged tables decrease a lot insert performances with PostgreSQL, so
262 use unlogged tables for sessions except for persistent sessions and
263 for OIDC sessions if you're using offline sessions
264 - Redis is the best for main usage, except when using SAML, Single-Sessions
265 and CAS
266 - Browseable::Postgres/PgHstore/PgJSON are the best solutions on
267 average
268
269 .. _performances-ldap-performances:
270
271 LDAP performances
272 ~~~~~~~~~~~~~~~~~
273
274 LDAP server can slow you down when you use LDAP groups retrieval. You
275 can avoid this by setting "memberOf" fields in your LDAP scheme:
276
277 .. code::
278
279 dn: uid=foo,dmdName=people,dc=example,dc=com
280 ...
281 memberOf: cn=admin,dmdName=groups,dc=example,dc=com
282 memberOf: cn=su,dmdName=groups,dc=example,dc=com
283
284 So instead of using LDAP groups retrieval, you just have to store
285 "memberOf" field in your exported variables. With OpenLDAP, you can use
286 the `memberof
287 overlay <http://www.openldap.org/doc/admin24/overlays.html#Reverse%20Group%20Membership%20Maintenance>`__
288 to do it automatically.
289
290
291 .. attention::
292
293 Don't forget to create an index on the field used to
294 find users (uid by default)
295
296
297 .. tip::
298
299 To avoid storing the full group DNs in session data, you can
300 use a macro to rewrite ``memberOf``:
301
302 - In \*Exported variables*, export the ``memberOf`` LDAP attribute as a
303 ``ldapGroups`` session variable
304
305 - key: ``ldapGroups``
306 - value: ``memberOf``
307
308 - Next, add a ``ldapGroups`` macro that will overwrite the exported
309 attribute
310
311 - key: ``ldapGroups``
312 - value:
313
314 ::
315
316 join("; ",($ldapGroups =~ /cn=(.*?),/g))
317
318 ``ldapGroups`` should now contain something like ``admin; su`` just like
319 it would if you had used the regular, slower group resolution mechanism.
320
321 You can use
322 :ref:`listMatch($ldapGroups, "some_group")<listMatch>` in your
323 access rules.
324
325 NGINX performances
326 ~~~~~~~~~~~~~~~~~~
327
328 To increase launch by web browser, for example to load js, css, or
329 fonts, Gzip compression can be activated.
330
331 Edit file /etc/nginx/mime.types Check those lines or add :
332
333 .. code-block:: perl
334
335 application/vnd.ms-fontobject eot;
336 application/x-font-ttf ttf;
337 application/font-woff woff;
338 font/opentype ott;
339
340 Edit file /etc/nginx/nginx.conf
341
342 .. code-block:: perl
343
344 gzip on; # active la compression Gzip
345 gzip_disable "msie6";
346
347 gzip_vary on;
348 gzip_proxied any;
349 gzip_comp_level 6;
350 gzip_buffers 16 8k;
351 gzip_http_version 1.1;
352 gzip_min_length 128;
353 gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/jpeg image/png image/svg+xml image/x-icon;
354
355 Restart NGINX and watch web-browser console.
356
357 Manager performances
358 --------------------
359
360 Disable unused modules
361 ~~~~~~~~~~~~~~~~~~~~~~
362
363 In lemonldap-ng.ini, set only modules that you will use. By default,
364 configuration, sessions explorer, notifications explorer and second
365 factor are enabled. Example:
366
367 .. code-block:: ini
368
369 [manager]
370 enabledModules = conf, sessions
371
372 Enable compactConf parameter
373 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
374
375 By enabling compactConf option, all unused configuration parameters are
376 removed. Could be usefull to shrink lemonldap-ng configuration file and
377 save space.
378
379 Go in Manager, ``General Parameters`` » ``Configuration reload`` »
380 ''Compact configuration file '' and set to ``On``.
381
382 Use static HTML files
383 ~~~~~~~~~~~~~~~~~~~~~
384
385 Once Manager is installed, browse enabled modules (configuration,
386 sessions, notifications) and save the web pages respectively under
387 ``manager.html``, ``sessions.html`` and ``notifications.html`` in the
388 ``DocumentRoot`` directory. Then replace this in Manager file of Apache
389 configuration:
390
391 .. code-block:: apache
392
393 RewriteRule "^/$" "/psgi/manager-server.fcgi" [PT]
394 # DirectoryIndex manager.html
395 # RewriteCond "%{REQUEST_FILENAME}" "!\.html$"
396 RewriteCond "%{REQUEST_FILENAME}" "!^/(?:static|doc|lib).*"
397 RewriteRule "^/(.+)$" "/psgi/manager-server.fcgi/$1" [PT]
398
399 by:
400
401 .. code-block:: apache
402
403 # RewriteRule "^/$" "/psgi/manager-server.fcgi" [PT]
404 DirectoryIndex manager.html
405 RewriteCond "%{REQUEST_FILENAME}" "!\.html$"
406 RewriteCond "%{REQUEST_FILENAME}" "!^/(?:static|doc|lib).*"
407 RewriteRule "^/(.+)$" "/psgi/manager-server.fcgi/$1" [PT]
408
409 So manager HTML templates will be no more generated by Perl but directly
410 given by the web server.