httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: svn commit: r645978 - in /httpd/httpd/trunk/modules: cache/ap_socache.h cache/mod_socache_dbm.c cache/mod_socache_dc.c cache/mod_socache_memcache.c cache/mod_socache_shmcb.c ssl/ssl_scache.c (fwd)
Date Fri, 11 Apr 2008 11:30:17 GMT

> 
> Author: jorton
> Date: Tue Apr  8 08:47:48 2008
> New Revision: 645978
> 
> URL: http://svn.apache.org/viewvc?rev=645978&view=rev
> Log:
> Adjust socache init interface to take sizing hints, and namespace tag
> for memcache:
> 
> * modules/cache/ap_socache.h (struct ap_socache_hints): New structure.
>   Change init callback to take namespace string and hints structure pointer.
> 
> * modules/cache/mod_socache_dc.c (socache_dc_init): Adjust accordingly.
> 
> * modules/cache/mod_socache_dbm.c (struct ap_socache_instance_t): Rename
>   timeout field to expiry_interval.
>   (socache_dbm_init, socache_dbm_create): Take expiry interval from
>   hints rather than hard-code to 30.
>   (socache_dbm_expire): Update for timeout field rename.
> 
> * modules/cache/mod_socache_shmcb.c (socache_shmcb_init): Adjust for
>   hints and namespace; adjust subcache index sizing heuristics to use
>   passed-in hints.
> 
> * modules/cache/mod_socache_memcache.c (struct ap_socache_instance_t):
>   Add tag, taglen fields.
>   (socache_mc_init): Store the passed-in namespace in instance
>   structure.
>   (mc_session_id2sz): Adjust to not take context, use configured
>   tag as string prefix, and not use a return value.
>   (socache_mc_store, socache_mc_retrieve, socache_mc_remove):
>   Adjust for mc_session_id2sz interface changes.
> 
> * modules/ssl/ssl_scache.c (ssl_scache_init): Pass namespace and hints
>   to socache provider init function.
> 
> Modified:
>     httpd/httpd/trunk/modules/cache/ap_socache.h
>     httpd/httpd/trunk/modules/cache/mod_socache_dbm.c
>     httpd/httpd/trunk/modules/cache/mod_socache_dc.c
>     httpd/httpd/trunk/modules/cache/mod_socache_memcache.c
>     httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c
>     httpd/httpd/trunk/modules/ssl/ssl_scache.c
> 

> Modified: httpd/httpd/trunk/modules/cache/mod_socache_memcache.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_socache_memcache.c?rev=645978&r1=645977&r2=645978&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/cache/mod_socache_memcache.c (original)
> +++ httpd/httpd/trunk/modules/cache/mod_socache_memcache.c Tue Apr  8 08:47:48 2008
> @@ -164,22 +167,21 @@
>      /* noop. */
>  }
>  
> -static char *mc_session_id2sz(const unsigned char *id, unsigned int idlen,
> -                              char *str, int strsize)
> +static void mc_session_id2sz(ap_socache_instance_t *ctx,
> +                             const unsigned char *id, unsigned int idlen,
> +                             char *buf, apr_size_t buflen)
>  {
> +    apr_size_t maxlen = (buflen - ctx->taglen) / 2;

What happens if ctx-taglen > buflen?

>      char *cp;
>      int n;
> -    int maxlen = (strsize - MC_TAG_LEN)/2;
>  
> -    cp = apr_cpystrn(str, MC_TAG, MC_TAG_LEN);
> +    cp = apr_cpystrn(buf, ctx->tag, ctx->taglen);

Se above. IMHO we should be defensive here and ensure that the last
parameter to apr_cpystrn is not larger than the buffer size.

>      for (n = 0; n < idlen && n < maxlen; n++) {
>          apr_snprintf(cp, 3, "%02X", (unsigned) id[n]);
>          cp += 2;
>      }
>  
>      *cp = '\0';
> -
> -    return str;
>  }
>  
>  static apr_status_t socache_mc_store(ap_socache_instance_t *ctx, server_rec *s, 
> @@ -188,21 +190,16 @@
>                                       unsigned char *ucaData, unsigned int nData)
>  {
>      char buf[MC_KEY_LEN];
> -    char *strkey = NULL;
>      apr_status_t rv;
>  
> -    strkey = mc_session_id2sz(id, idlen, buf, sizeof(buf));
> -    if(!strkey) {
> -        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "scache_mc: Key generation borked.");
> -        return APR_EGENERAL;
> -    }
> +    mc_session_id2sz(ctx, id, idlen, buf, sizeof(buf));
>  
> -    rv = apr_memcache_set(ctx->mc, strkey, (char*)ucaData, nData, timeout, 0);
> +    rv = apr_memcache_set(ctx->mc, buf, (char*)ucaData, nData, timeout, 0);
>  
>      if (rv != APR_SUCCESS) {
>          ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
>                       "scache_mc: error setting key '%s' "
> -                     "with %d bytes of data", strkey, nData);
> +                     "with %d bytes of data", buf, nData);
>          return rv;
>      }
>  
> @@ -217,21 +214,14 @@
>  {
>      apr_size_t der_len;
>      char buf[MC_KEY_LEN], *der;
> -    char *strkey = NULL;
>      apr_status_t rv;
>  
> -    strkey = mc_session_id2sz(id, idlen, buf, sizeof(buf));
> -
> -    if (!strkey) {
> -        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
> -                     "scache_mc: Key generation borked.");
> -        return APR_EGENERAL;
> -    }
> +    mc_session_id2sz(ctx, id, idlen, buf, sizeof(buf));
>  
>      /* ### this could do with a subpool, but _getp looks like it will
>       * eat memory like it's going out of fashion anyway. */
>  
> -    rv = apr_memcache_getp(ctx->mc, p, strkey,
> +    rv = apr_memcache_getp(ctx->mc, p, buf,
>                             &der, &der_len, NULL);
>      if (rv) {
>          if (rv != APR_NOTFOUND) {
> 
> Modified: httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c?rev=645978&r1=645977&r2=645978&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c (original)
> +++ httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c Tue Apr  8 08:47:48 2008
> @@ -348,16 +351,10 @@
>                   shm_segsize);
>      /* Discount the header */
>      shm_segsize -= sizeof(SHMCBHeader);
> -    /* Select the number of subcaches to create and how many indexes each
> -     * should contain based on the size of the memory (the header has already
> -     * been subtracted). Typical non-client-auth sslv3/tlsv1 sessions are
> -     * around 180 bytes (148 bytes data and 32 bytes for the id), so
> -     * erring to division by 150 helps ensure we would exhaust data
> -     * storage before index storage (except sslv2, where it's
> -     * *slightly* the other way). From there, we select the number of
> -     * subcaches to be a power of two, such that the number of indexes
> -     * per subcache at least twice the number of subcaches. */
> -    num_idx = (shm_segsize) / 150;
> +    /* Select index size based on average object size hints, if given. */
> +    avg_obj_size = hints && hints->avg_obj_size ? hints->avg_obj_size
: 150;
> +    avg_id_len = hints && hints->avg_id_len ? hints->avg_id_len : 30;
> +    num_idx = (shm_segsize) / (avg_obj_size + avg_id_len);

Hm. Before the change the default factor was 1 / 150 now it is 1 / 180. Is
this correct?

Regards

RĂ¼diger

Mime
View raw message