[ThreadPool] Allow heavier initialization when using --server flag
authorAndrés G. Aragoneses <knocte@gmail.com>
Tue, 6 Aug 2013 08:32:54 +0000 (10:32 +0200)
committerAndrés G. Aragoneses <knocte@gmail.com>
Tue, 6 Aug 2013 08:32:54 +0000 (10:32 +0200)
Create on demand up to min_threads to avoid startup penalty, avoiding
throttling of threadpool worker thread creation (for now, using
a --server flag) at initialization.

When throttling happens, operations such as parallel https requests were
slowed down significantly due to all of the threads created in order
to complete the SSL operations.

Based on @kamalaboulhosn's patch (https://github.com/mono/mono/pull/640/files)

man/mono.1
mono/metadata/mono-config.c
mono/metadata/mono-config.h
mono/metadata/threadpool.c
mono/mini/driver.c

index 318c0586d0fe9d191e229d31ac4aedb30824bfcb..54ad76931cb522f3ddaf9104b532a859ebae876f 100644 (file)
@@ -417,7 +417,7 @@ the global assembly cache is always trusted.
 .TP
 \fB--server\fR
 Configures the virtual machine to be better suited for server
-operations (currently, a no-op).
+operations (currently, allows a heavier threadpool initialization).
 .TP
 \fB--verify-all\fR 
 Verifies mscorlib and assemblies in the global
index 88991604f853f41ed209d32f50c64ba2ac7897db..01dd11c1df83febf93a47d07bebc135bcad8c4da 100644 (file)
@@ -790,3 +790,17 @@ mono_config_parse_assembly_bindings (const char *filename, int amajor, int amino
        mono_config_parse_file_with_context (&state, filename);
 }
 
+static gboolean mono_server_mode = FALSE;
+
+void
+mono_config_set_server_mode (gboolean server_mode)
+{
+       mono_server_mode = server_mode;
+}
+
+gboolean
+mono_config_is_server_mode (void)
+{
+       return mono_server_mode;
+}
+
index 0b46425cdb5985a4a5a094a29b811266f3480df9..d2496e2c4ce5f7280efe8d468db7e7246012c8c0 100644 (file)
@@ -25,6 +25,9 @@ void mono_config_parse_memory (const char *buffer);
 
 const char* mono_config_string_for_assembly_file (const char *filename);
 
+void mono_config_set_server_mode (gboolean server_mode);
+gboolean mono_config_is_server_mode (void);
+
 MONO_END_DECLS
 
 #endif /* __MONO_METADATA_CONFIG_H__ */
index 971ca9314e8a46816995afe853535dde147bb6f7..fa4cd1a4e7b30cd45eb00b06a6b3905277600e4d 100644 (file)
@@ -19,6 +19,7 @@
 #include <mono/metadata/threadpool-internals.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/environment.h>
+#include <mono/metadata/mono-config.h>
 #include <mono/metadata/mono-mlist.h>
 #include <mono/metadata/mono-perfcounters.h>
 #include <mono/metadata/socket-io.h>
@@ -1064,8 +1065,10 @@ threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs)
                }
                /* Create on demand up to min_threads to avoid startup penalty for apps that don't use
                 * the threadpool that much
-               * mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, tp, TRUE, FALSE, SMALL_STACK);
-               */
+                */
+               if (mono_config_is_server_mode ()) {
+                       mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, tp, TRUE, FALSE, SMALL_STACK);
+               }
        }
 
        for (i = 0; i < njobs; i++) {
index b7574c1e7b45270159751278888efeb023a84e77..02fede1c2af8969fad3f90c9e2ba9ebac0b8f051 100644 (file)
@@ -1715,9 +1715,10 @@ mono_main (int argc, char* argv[])
                        }
                } else if (strcmp (argv [i], "--desktop") == 0) {
                        mono_gc_set_desktop_mode ();
-                       /* Put desktop-specific optimizations here */
+                       /* Put more desktop-specific optimizations here */
                } else if (strcmp (argv [i], "--server") == 0){
-                       /* Put server-specific optimizations here */
+                       mono_config_set_server_mode (TRUE);
+                       /* Put more server-specific optimizations here */
                } else if (strcmp (argv [i], "--inside-mdb") == 0) {
                        action = DO_DEBUGGER;
                } else if (strncmp (argv [i], "--wapi=", 7) == 0) {