You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2014/07/17 17:00:34 UTC

svn commit: r1611380 - /subversion/trunk/subversion/libsvn_subr/cache-membuffer.c

Author: stefan2
Date: Thu Jul 17 15:00:33 2014
New Revision: 1611380

URL: http://svn.apache.org/r1611380
Log:
Work around for the poor performance of APR reader / writer locks on Windows.
Basically, fall back to 1.7 code on Win32 by using a simple mutex.

This resulted in a 35% increase in throughput for a 'null-export' over
ra_serf from hot SVN caches with revprop caching enabled.  OTOH, this may
cost us some scalability with ra_svn on high-speed (>1Gb) networks.

* subversion/libsvn_subr/cache-membuffer.c
  (USE_SIMPLE_MUTEX): New flag.  Set depending on whether we need to fall
                      back to a simple locking scheme.
  (svn_membuffer_t): Select lock type at compile time.
  (read_lock_cache,
   write_lock_cache,
   force_write_lock_cache,
   unlock_cache): Use the simple mutex lock when selected.
  (svn_cache__membuffer_cache_create): Initialize the correct lock type and
                                       disable the counter_mutex if redundant.

Modified:
    subversion/trunk/subversion/libsvn_subr/cache-membuffer.c

Modified: subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c?rev=1611380&r1=1611379&r2=1611380&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-membuffer.c Thu Jul 17 15:00:33 2014
@@ -115,6 +115,21 @@
  * on their hash key.
  */
 
+/* APR's read-write lock implementation on Windows is horribly inefficient.
+ * Even with very low contention a runtime overhead of 35% percent has been
+ * measured for 'svn-bench null-export' over ra_serf.
+ *
+ * Use a simple mutex on Windows.  Because there is one mutex per segment,
+ * large machines should (and usually can) be configured with large caches
+ * such that read contention is kept low.  This is basically the situation
+ * we head before 1.8.
+ */
+#ifdef WIN32
+#  define USE_SIMPLE_MUTEX 1
+#else
+#  define USE_SIMPLE_MUTEX 0
+#endif
+
 /* For more efficient copy operations, let's align all data items properly.
  * Must be a power of 2.
  */
@@ -581,11 +596,15 @@ struct svn_membuffer_t
    * the cache's creator doesn't feel the cache needs to be
    * thread-safe.
    */
+#  if USE_SIMPLE_MUTEX
+  svn_mutex__t *lock;
+#  else
   apr_thread_rwlock_t *lock;
+#  endif
 
   /* If set, write access will wait until they get exclusive access.
    * Otherwise, they will become no-ops if the segment is currently
-   * read-locked.
+   * read-locked.  Only used when LOCK is an r/w lock.
    */
   svn_boolean_t allow_blocking_writes;
 #endif
@@ -611,6 +630,9 @@ static svn_error_t *
 read_lock_cache(svn_membuffer_t *cache)
 {
 #if APR_HAS_THREADS
+#  if USE_SIMPLE_MUTEX
+  return svn_mutex__lock(cache->lock);
+#  else
   if (cache->lock)
   {
     apr_status_t status = apr_thread_rwlock_rdlock(cache->lock);
@@ -627,6 +649,12 @@ static svn_error_t *
 write_lock_cache(svn_membuffer_t *cache, svn_boolean_t *success)
 {
 #if APR_HAS_THREADS
+#  if USE_SIMPLE_MUTEX
+
+  return svn_mutex__lock(cache->lock);
+
+#  else
+
   if (cache->lock)
     {
       apr_status_t status;
@@ -648,6 +676,8 @@ write_lock_cache(svn_membuffer_t *cache,
         return svn_error_wrap_apr(status,
                                   _("Can't write-lock cache mutex"));
     }
+
+#  endif
 #endif
   return SVN_NO_ERROR;
 }
@@ -659,10 +689,18 @@ static svn_error_t *
 force_write_lock_cache(svn_membuffer_t *cache)
 {
 #if APR_HAS_THREADS
+#  if USE_SIMPLE_MUTEX
+
+  return svn_mutex__lock(cache->lock);
+
+#  else
+
   apr_status_t status = apr_thread_rwlock_wrlock(cache->lock);
   if (status)
     return svn_error_wrap_apr(status,
                               _("Can't write-lock cache mutex"));
+
+#  endif
 #endif
   return SVN_NO_ERROR;
 }
@@ -674,6 +712,12 @@ static svn_error_t *
 unlock_cache(svn_membuffer_t *cache, svn_error_t *err)
 {
 #if APR_HAS_THREADS
+#  if USE_SIMPLE_MUTEX
+
+  return svn_mutex__unlock(cache->lock, SVN_NO_ERROR);
+
+#  else
+
   if (cache->lock)
   {
     apr_status_t status = apr_thread_rwlock_unlock(cache->lock);
@@ -683,6 +727,8 @@ unlock_cache(svn_membuffer_t *cache, svn
     if (status)
       return svn_error_wrap_apr(status, _("Can't unlock cache mutex"));
   }
+
+#  endif
 #endif
   return err;
 }
@@ -1768,6 +1814,12 @@ svn_cache__membuffer_cache_create(svn_me
        * the cache's creator doesn't feel the cache needs to be
        * thread-safe.
        */
+#  if USE_SIMPLE_MUTEX
+
+      SVN_ERR(svn_mutex__init(&c[seg].lock, thread_safe, FALSE, pool));
+
+#  else
+
       c[seg].lock = NULL;
       if (thread_safe)
         {
@@ -1777,12 +1829,17 @@ svn_cache__membuffer_cache_create(svn_me
             return svn_error_wrap_apr(status, _("Can't create cache mutex"));
         }
 
+#  endif
+
       /* Select the behavior of write operations.
        */
       c[seg].allow_blocking_writes = allow_blocking_writes;
 #endif
 
-      SVN_ERR(svn_mutex__init(&c[seg].counter_mutex, thread_safe, FALSE,
+      /* Since a simple mutex already guarantees fully serialized access,
+         we need this mutex only when we use multple-reader-1-writer locks. */
+      SVN_ERR(svn_mutex__init(&c[seg].counter_mutex,
+                              thread_safe && !USE_SIMPLE_MUTEX, FALSE,
                               pool));
     }
 



Re: svn commit: r1611380 - /subversion/trunk/subversion/libsvn_subr/cache-membuffer.c

Posted by Ivan Zhakov <iv...@visualsvn.com>.
On 22 December 2014 at 15:01, Ivan Zhakov <iv...@visualsvn.com> wrote:
> On 17 July 2014 at 18:00,  <st...@apache.org> wrote:
>> Author: stefan2
>> Date: Thu Jul 17 15:00:33 2014
>> New Revision: 1611380
>>
>> URL: http://svn.apache.org/r1611380
>> Log:
>> Work around for the poor performance of APR reader / writer locks on Windows.
>> Basically, fall back to 1.7 code on Win32 by using a simple mutex.
>>
>> This resulted in a 35% increase in throughput for a 'null-export' over
>> ra_serf from hot SVN caches with revprop caching enabled.  OTOH, this may
>> cost us some scalability with ra_svn on high-speed (>1Gb) networks.
>>
>> * subversion/libsvn_subr/cache-membuffer.c
>>   (USE_SIMPLE_MUTEX): New flag.  Set depending on whether we need to fall
>>                       back to a simple locking scheme.
>>   (svn_membuffer_t): Select lock type at compile time.
>>   (read_lock_cache,
>>    write_lock_cache,
>>    force_write_lock_cache,
>>    unlock_cache): Use the simple mutex lock when selected.
>>   (svn_cache__membuffer_cache_create): Initialize the correct lock type and
>>                                        disable the counter_mutex if redundant.
>>
>> Modified:
>>     subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
>>
> [...]
>> @@ -674,6 +712,12 @@ static svn_error_t *
>>  unlock_cache(svn_membuffer_t *cache, svn_error_t *err)
>>  {
>>  #if APR_HAS_THREADS
>> +#  if USE_SIMPLE_MUTEX
>> +
>> +  return svn_mutex__unlock(cache->lock, SVN_NO_ERROR);
>> +
>> +#  else
>> +
>>    if (cache->lock)
>>    {
>>      apr_status_t status = apr_thread_rwlock_unlock(cache->lock);
>> @@ -683,6 +727,8 @@ unlock_cache(svn_membuffer_t *cache, svn
>>      if (status)
>>        return svn_error_wrap_apr(status, _("Can't unlock cache mutex"));
>>    }
>> +
>> +#  endif
>>  #endif
>>    return err;
>>  }
> The provided ERR argument is ignored in USE_SIMPLE_MUTEX codepath. So
> any error from cache serializer will be ignored and invalid result
> will be used.
>
I've fixed this problem in r1647339 and another similar problem in r1647372.

-- 
Ivan Zhakov

Re: svn commit: r1611380 - /subversion/trunk/subversion/libsvn_subr/cache-membuffer.c

Posted by Stefan Fuhrmann <st...@wandisco.com>.
On Mon, Dec 22, 2014 at 1:01 PM, Ivan Zhakov <iv...@visualsvn.com> wrote:

> On 17 July 2014 at 18:00,  <st...@apache.org> wrote:
> > Author: stefan2
> > Date: Thu Jul 17 15:00:33 2014
> > New Revision: 1611380
> >
> > URL: http://svn.apache.org/r1611380
> > Log:
> > Work around for the poor performance of APR reader / writer locks on
> Windows.
> > Basically, fall back to 1.7 code on Win32 by using a simple mutex.
> >
> > This resulted in a 35% increase in throughput for a 'null-export' over
> > ra_serf from hot SVN caches with revprop caching enabled.  OTOH, this may
> > cost us some scalability with ra_svn on high-speed (>1Gb) networks.
> >
> > * subversion/libsvn_subr/cache-membuffer.c
> >   (USE_SIMPLE_MUTEX): New flag.  Set depending on whether we need to fall
> >                       back to a simple locking scheme.
> >   (svn_membuffer_t): Select lock type at compile time.
> >   (read_lock_cache,
> >    write_lock_cache,
> >    force_write_lock_cache,
> >    unlock_cache): Use the simple mutex lock when selected.
> >   (svn_cache__membuffer_cache_create): Initialize the correct lock type
> and
> >                                        disable the counter_mutex if
> redundant.
> >
> > Modified:
> >     subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
> >
> [...]
> > @@ -674,6 +712,12 @@ static svn_error_t *
> >  unlock_cache(svn_membuffer_t *cache, svn_error_t *err)
> >  {
> >  #if APR_HAS_THREADS
> > +#  if USE_SIMPLE_MUTEX
> > +
> > +  return svn_mutex__unlock(cache->lock, SVN_NO_ERROR);
> > +
> > +#  else
> > +
> >    if (cache->lock)
> >    {
> >      apr_status_t status = apr_thread_rwlock_unlock(cache->lock);
> > @@ -683,6 +727,8 @@ unlock_cache(svn_membuffer_t *cache, svn
> >      if (status)
> >        return svn_error_wrap_apr(status, _("Can't unlock cache mutex"));
> >    }
> > +
> > +#  endif
> >  #endif
> >    return err;
> >  }
> The provided ERR argument is ignored in USE_SIMPLE_MUTEX codepath. So
> any error from cache serializer will be ignored and invalid result
> will be used.
>

Thanks for fixing!

-- Stefan^2.

Re: svn commit: r1611380 - /subversion/trunk/subversion/libsvn_subr/cache-membuffer.c

Posted by Ivan Zhakov <iv...@visualsvn.com>.
On 17 July 2014 at 18:00,  <st...@apache.org> wrote:
> Author: stefan2
> Date: Thu Jul 17 15:00:33 2014
> New Revision: 1611380
>
> URL: http://svn.apache.org/r1611380
> Log:
> Work around for the poor performance of APR reader / writer locks on Windows.
> Basically, fall back to 1.7 code on Win32 by using a simple mutex.
>
> This resulted in a 35% increase in throughput for a 'null-export' over
> ra_serf from hot SVN caches with revprop caching enabled.  OTOH, this may
> cost us some scalability with ra_svn on high-speed (>1Gb) networks.
>
> * subversion/libsvn_subr/cache-membuffer.c
>   (USE_SIMPLE_MUTEX): New flag.  Set depending on whether we need to fall
>                       back to a simple locking scheme.
>   (svn_membuffer_t): Select lock type at compile time.
>   (read_lock_cache,
>    write_lock_cache,
>    force_write_lock_cache,
>    unlock_cache): Use the simple mutex lock when selected.
>   (svn_cache__membuffer_cache_create): Initialize the correct lock type and
>                                        disable the counter_mutex if redundant.
>
> Modified:
>     subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
>
[...]
> @@ -674,6 +712,12 @@ static svn_error_t *
>  unlock_cache(svn_membuffer_t *cache, svn_error_t *err)
>  {
>  #if APR_HAS_THREADS
> +#  if USE_SIMPLE_MUTEX
> +
> +  return svn_mutex__unlock(cache->lock, SVN_NO_ERROR);
> +
> +#  else
> +
>    if (cache->lock)
>    {
>      apr_status_t status = apr_thread_rwlock_unlock(cache->lock);
> @@ -683,6 +727,8 @@ unlock_cache(svn_membuffer_t *cache, svn
>      if (status)
>        return svn_error_wrap_apr(status, _("Can't unlock cache mutex"));
>    }
> +
> +#  endif
>  #endif
>    return err;
>  }
The provided ERR argument is ignored in USE_SIMPLE_MUTEX codepath. So
any error from cache serializer will be ignored and invalid result
will be used.

-- 
Ivan Zhakov