Browse Source

Now using 4 worker threads (multithreading is enabled)

Steven Engler 4 years ago
parent
commit
7f72d9b63c
2 changed files with 8 additions and 3 deletions
  1. 1 1
      src/app/config/config.c
  2. 7 2
      src/core/mainloop/mainloop.c

+ 1 - 1
src/app/config/config.c

@@ -7992,7 +7992,7 @@ init_libevent(const or_options_t *options)
   cfg.msec_per_tick = options->TokenBucketRefillInterval;
 
   /* Don't use any additional eventloops (only use the mainloop). */
-  int num_additional_eventloops = 0;
+  int num_additional_eventloops = 4;
 
   tor_libevent_initialize(&cfg, num_additional_eventloops);
   log_info(LD_CONFIG, "Initializing libevent with %d additional eventloops.",

+ 7 - 2
src/core/mainloop/mainloop.c

@@ -243,6 +243,8 @@ note_that_we_maybe_cant_complete_circuits(void)
   can_complete_circuits = 0;
 }
 
+static unsigned long eventloop_counter = 0;
+
 /** Add <b>conn</b> to the array of connections that we can poll on.  The
  * connection's socket must be set; the connection starts out
  * non-reading and non-writing.
@@ -282,8 +284,11 @@ connection_add_impl(connection_t *conn, int is_connecting)
   } else {
     tor_assert(conn->type == CONN_TYPE_OR);
 
-    error_t rv = safe_connection_register_events(conn->safe_conn,
-                                                 tor_libevent_get_base());
+    int eventloop_index = 1 + (eventloop_counter%(get_num_eventloops()-1));
+    struct event_base *base = get_eventloop(eventloop_index);
+    eventloop_counter += 1;
+    //struct event_base *base = tor_libevent_get_base();
+    error_t rv = safe_connection_register_events(conn->safe_conn, base);
 
     if (rv != E_SUCCESS) {
       smartlist_remove(connection_array, conn);