View Issue Details

IDProjectCategoryView StatusLast Update
0002899libmicrohttpdperformancepublic2013-07-19 13:36
Reportermatt.holiday Assigned ToChristian Grothoff  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version0.9.26 
Target Version0.9.28Fixed in Version0.9.28 
Summary0002899: Patch to control memory pool growth with a new option
DescriptionThis patch adds an option MHD_OPTION_CONNECTION_MEMORY_INCREMENT to provide a non-default memory increment value

This allows the server incorporating microHTTPD to control the memory growth of the pool, by providing a larger increment so memory expands more quickly for large data transfers

MHD_BUF_INC_SIZE remains the default if this option is not set
Additional InformationSee patch file
TagsNo tags attached.
Attached Files
dynamic_buffer_increase-0.9.26.patch (4,350 bytes)   
diff --recursive --unified --new-file a/src/daemon/connection.c b/src/daemon/connection.c
--- a/src/daemon/connection.c	2013-02-01 17:42:25.000000000 -0700
+++ b/src/daemon/connection.c	2013-06-20 00:58:39.070870565 -0600
@@ -653,13 +653,13 @@
                              connection->read_buffer,
                              connection->read_buffer_size,
                              connection->read_buffer_size * 2 +
-                             MHD_BUF_INC_SIZE + 1);
+                             connection->daemon->pool_increment + 1);
   if (NULL == buf)
     return MHD_NO;
   /* we can actually grow the buffer, do it! */
   connection->read_buffer = buf;
   connection->read_buffer_size =
-    connection->read_buffer_size * 2 + MHD_BUF_INC_SIZE;
+    connection->read_buffer_size * 2 + connection->daemon->pool_increment;
   return MHD_YES;
 }
 
@@ -1084,7 +1084,7 @@
                                       connection->read_buffer,
                                       connection->read_buffer_size,
                                       connection->read_buffer_size * 2 +
-                                      MHD_BUF_INC_SIZE);
+                                      connection->daemon->pool_increment);
           if (NULL == rbuf)
             {
               transmit_error_response (connection,
@@ -1096,7 +1096,7 @@
           else
             {
               connection->read_buffer_size =
-                connection->read_buffer_size * 2 + MHD_BUF_INC_SIZE;
+                connection->read_buffer_size * 2 + connection->daemon->pool_increment;
               connection->read_buffer = rbuf;
             }
         }
@@ -1895,7 +1895,7 @@
     return MHD_YES;
   /* make sure "read" has a reasonable number of bytes
      in buffer to use per system call (if possible) */
-  if (connection->read_buffer_offset + MHD_BUF_INC_SIZE >
+  if (connection->read_buffer_offset + connection->daemon->pool_increment >
       connection->read_buffer_size)
     try_grow_read_buffer (connection);
   if (MHD_NO == do_read (connection))
diff --recursive --unified --new-file a/src/daemon/daemon.c b/src/daemon/daemon.c
--- a/src/daemon/daemon.c	2013-02-28 17:11:48.000000000 -0700
+++ b/src/daemon/daemon.c	2013-06-20 01:00:05.775033429 -0600
@@ -1796,6 +1796,9 @@
         case MHD_OPTION_CONNECTION_MEMORY_LIMIT:
           daemon->pool_size = va_arg (ap, size_t);
           break;
+        case MHD_OPTION_CONNECTION_MEMORY_INCREMENT:
+          daemon->pool_increment= va_arg (ap, size_t);
+          break;
         case MHD_OPTION_CONNECTION_LIMIT:
           daemon->max_connections = va_arg (ap, unsigned int);
           break;
@@ -1919,6 +1922,7 @@
 		{
 		  /* all options taking 'size_t' */
 		case MHD_OPTION_CONNECTION_MEMORY_LIMIT:
+		case MHD_OPTION_CONNECTION_MEMORY_INCREMENT:
 		case MHD_OPTION_THREAD_STACK_SIZE:
 		  if (MHD_YES != parse_options (daemon,
 						servaddr,
@@ -2151,6 +2155,7 @@
   daemon->default_handler_cls = dh_cls;
   daemon->max_connections = MHD_MAX_CONNECTIONS_DEFAULT;
   daemon->pool_size = MHD_POOL_SIZE_DEFAULT;
+  daemon->pool_increment = MHD_BUF_INC_SIZE;
   daemon->unescape_callback = &MHD_http_unescape;
   daemon->connection_timeout = 0;       /* no timeout */
   daemon->wpipe[0] = -1;
diff --recursive --unified --new-file a/src/daemon/internal.h b/src/daemon/internal.h
--- a/src/daemon/internal.h	2012-10-23 07:43:25.000000000 -0600
+++ b/src/daemon/internal.h	2013-06-20 00:58:39.078870569 -0600
@@ -899,6 +899,11 @@
   size_t pool_size;
 
   /**
+   * Increment for growth of the per-connection memory pools.
+   */
+  size_t pool_increment;
+
+  /**
    * Size of threads created by MHD.
    */
   size_t thread_stack_size;
diff --recursive --unified --new-file a/src/include/microhttpd.h b/src/include/microhttpd.h
--- a/src/include/microhttpd.h	2013-03-30 15:23:28.000000000 -0600
+++ b/src/include/microhttpd.h	2013-06-20 00:58:39.078870569 -0600
@@ -626,7 +626,13 @@
    * HTTPS daemon for client authentification.
    * This option should be followed by a "const char*" argument.
    */
-  MHD_OPTION_HTTPS_MEM_TRUST =20
+  MHD_OPTION_HTTPS_MEM_TRUST = 20,
+
+  /**
+   * Increment to use for growing the read buffer (followed by a
+   * size_t). Must fit within MHD_OPTION_CONNECTION_MEMORY_LIMIT.
+   */
+  MHD_OPTION_CONNECTION_MEMORY_INCREMENT = 21
 };
 
 

Activities

Christian Grothoff

2013-07-05 12:12

manager   ~0007203

Fixed in SVN 27754.

Issue History

Date Modified Username Field Change
2013-06-20 18:45 matt.holiday New Issue
2013-06-20 18:45 matt.holiday File Added: dynamic_buffer_increase-0.9.26.patch
2013-06-25 12:10 Christian Grothoff Assigned To => Christian Grothoff
2013-06-25 12:10 Christian Grothoff Status new => assigned
2013-06-25 12:10 Christian Grothoff Target Version => 0.9.28
2013-07-05 12:12 Christian Grothoff Note Added: 0007203
2013-07-05 12:12 Christian Grothoff Status assigned => resolved
2013-07-05 12:12 Christian Grothoff Fixed in Version => 0.9.28
2013-07-05 12:12 Christian Grothoff Resolution open => fixed
2013-07-19 13:36 Christian Grothoff Status resolved => closed