aboutsummaryrefslogtreecommitdiff
path: root/doh
diff options
context:
space:
mode:
authorMike Yu <yumike@google.com>2022-01-04 20:13:58 +0800
committerMike Yu <yumike@google.com>2022-01-06 13:27:47 +0000
commit42a735327fcf9773e25dca0e4ab86de02cb7eb00 (patch)
tree593b86753ac2923ddd9f1ff9bd81a2612af8f12d /doh
parent9b748ee32cc6118c5c24b49ff938a99554d8f599 (diff)
downloadDnsResolver-42a735327fcf9773e25dca0e4ab86de02cb7eb00.tar.gz
DoH: Change to use runtime with current thread scheduler in doh_query()
Perfetto shows that using runtime with multi-thread scheduler in doh_query() results in 8 threads created and terminated every time doh_query() is called, which takes approximately 2 ms. So, change the code to use a runtime with current thread scheduler. This approximately reduces the time overhead of doh_query() from 2 ms to 0.5 ms. Bug: 212364676 Test: cd packages/modules/DnsResolver && atest Change-Id: I7652e6982b1485ee435b6399798b19badd264500
Diffstat (limited to 'doh')
-rw-r--r--doh/ffi.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/doh/ffi.rs b/doh/ffi.rs
index 5b4c9858..1b4087a9 100644
--- a/doh/ffi.rs
+++ b/doh/ffi.rs
@@ -29,7 +29,7 @@ use std::os::unix::io::RawFd;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::{ptr, slice};
-use tokio::runtime::Runtime;
+use tokio::runtime::Builder;
use tokio::sync::oneshot;
use tokio::task;
use url::Url;
@@ -275,7 +275,7 @@ pub unsafe extern "C" fn doh_query(
return DOH_RESULT_CAN_NOT_SEND;
}
- if let Ok(rt) = Runtime::new() {
+ if let Ok(rt) = Builder::new_current_thread().enable_all().build() {
let local = task::LocalSet::new();
match local.block_on(&rt, async { timeout(t, resp_rx).await }) {
Ok(v) => match v {