From 67efef0742fd4851c2e41a4ed1c0cb142c1047e9 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Jun 05 2018 12:13:48 +0000 Subject: Ticket 49732 - Optimize resource limit checking for rootdn issued searches Description: When performing a search as the Directory Manager resource limits should not apply. So there is no need to "get" the limits if its a Directory Manager initiated search. I'm seeing around 2% performance increase when we skip getting the resource limits. https://pagure.io/389-ds-base/issue/49732 Reviewed by: tbordaz (Thanks!) Signed-off-by: Mark Reynolds --- diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c index c39599d..966131c 100644 --- a/ldap/servers/slapd/back-ldbm/ldbm_search.c +++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c @@ -52,37 +52,50 @@ compute_lookthrough_limit(Slapi_PBlock *pb, struct ldbminfo *li) Slapi_Connection *conn = NULL; int limit; Slapi_Operation *op; + int isroot = 0; + slapi_pblock_get(pb, SLAPI_REQUESTOR_ISROOT, &isroot); slapi_pblock_get(pb, SLAPI_CONNECTION, &conn); slapi_pblock_get(pb, SLAPI_OPERATION, &op); - if (slapi_reslimit_get_integer_limit(conn, - li->li_reslimit_lookthrough_handle, &limit) != SLAPI_RESLIMIT_STATUS_SUCCESS) { - /* - * no limit associated with binder/connection or some other error - * occurred. use the default. - */ - int isroot = 0; - - slapi_pblock_get(pb, SLAPI_REQUESTOR_ISROOT, &isroot); - if (isroot) { - limit = -1; + if (isroot) { + limit = -1; + } else { + if (op_is_pagedresults(op)) { + if (slapi_reslimit_get_integer_limit(conn, + li->li_reslimit_pagedlookthrough_handle, &limit) != SLAPI_RESLIMIT_STATUS_SUCCESS) + { + PR_Lock(li->li_config_mutex); + if (li->li_pagedlookthroughlimit) { + limit = li->li_pagedlookthroughlimit; + } else { + /* No paged search lookthroughlimit, so use DB lookthroughlimit. + * First check if we have a "resource limit" that applies to this + * connection, otherwise use the global DB lookthroughlimit + */ + if (slapi_reslimit_get_integer_limit(conn, + li->li_reslimit_lookthrough_handle, &limit) != SLAPI_RESLIMIT_STATUS_SUCCESS) + { + /* Default to global DB lookthroughlimit */ + limit = li->li_lookthroughlimit; + } + } + /* else set above */ + PR_Unlock(li->li_config_mutex); + } } else { - PR_Lock(li->li_config_mutex); - limit = li->li_lookthroughlimit; - PR_Unlock(li->li_config_mutex); - } - } - - if (op_is_pagedresults(op)) { - if (slapi_reslimit_get_integer_limit(conn, - li->li_reslimit_pagedlookthrough_handle, &limit) != SLAPI_RESLIMIT_STATUS_SUCCESS) { - PR_Lock(li->li_config_mutex); - if (li->li_pagedlookthroughlimit) { - limit = li->li_pagedlookthroughlimit; + /* Regular search */ + if (slapi_reslimit_get_integer_limit(conn, + li->li_reslimit_lookthrough_handle, &limit) != SLAPI_RESLIMIT_STATUS_SUCCESS) + { + /* + * no limit associated with binder/connection or some other error + * occurred. use the default. + */ + PR_Lock(li->li_config_mutex); + limit = li->li_lookthroughlimit; + PR_Unlock(li->li_config_mutex); } - /* else set above */ - PR_Unlock(li->li_config_mutex); } } return (limit); diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c index 50b7ae8..74f2c24 100644 --- a/ldap/servers/slapd/opshared.c +++ b/ldap/servers/slapd/opshared.c @@ -1483,17 +1483,16 @@ compute_limits(Slapi_PBlock *pb) /* * Compute the time limit. */ - if (slapi_reslimit_get_integer_limit(pb_conn, - timelimit_reslimit_handle, &max_timelimit) != SLAPI_RESLIMIT_STATUS_SUCCESS) { + if (isroot) { + max_timelimit = -1; /* no limit */ + } else if (slapi_reslimit_get_integer_limit(pb_conn, + timelimit_reslimit_handle, &max_timelimit) != SLAPI_RESLIMIT_STATUS_SUCCESS) + { /* * no limit associated with binder/connection or some other error * occurred. use the default maximum. - */ - if (isroot) { - max_timelimit = -1; /* no limit */ - } else { - max_timelimit = be->be_timelimit; - } + */ + max_timelimit = be->be_timelimit; } if (requested_timelimit) { @@ -1519,30 +1518,31 @@ set_timelimit: /* * Compute the size limit. */ - if (slapi_reslimit_get_integer_limit(pb_conn, - sizelimit_reslimit_handle, &max_sizelimit) != SLAPI_RESLIMIT_STATUS_SUCCESS) { - /* - * no limit associated with binder/connection or some other error - * occurred. use the default maximum. - */ - if (isroot) { - max_sizelimit = -1; /* no limit */ - } else { - max_sizelimit = be->be_sizelimit; - } - } - - if (op_is_pagedresults(op)) { + if (isroot) { + max_sizelimit = -1; /* no limit */ + } else { if (slapi_reslimit_get_integer_limit(pb_conn, - pagedsizelimit_reslimit_handle, &max_sizelimit) != SLAPI_RESLIMIT_STATUS_SUCCESS) { + sizelimit_reslimit_handle, &max_sizelimit) != SLAPI_RESLIMIT_STATUS_SUCCESS) + { /* * no limit associated with binder/connection or some other error * occurred. use the default maximum. */ - if (be->be_pagedsizelimit) { - max_sizelimit = be->be_pagedsizelimit; + max_sizelimit = be->be_sizelimit; + } + + if (op_is_pagedresults(op)) { + if (slapi_reslimit_get_integer_limit(pb_conn, + pagedsizelimit_reslimit_handle, &max_sizelimit) != SLAPI_RESLIMIT_STATUS_SUCCESS) { + /* + * no limit associated with binder/connection or some other error + * occurred. use the default maximum. + */ + if (be->be_pagedsizelimit) { + max_sizelimit = be->be_pagedsizelimit; + } + /* else was already set above */ } - /* else was already set above */ } }