Explorar o código

Add a test for the average latency

Most of the latency comes from the two thread pools. Each one adds
about 15-20ms to the overall latency. The rest of the code contributes
to the other 15-20ms.
Jing Yang %!s(int64=5) %!d(string=hai) anos
pai
achega
803d25b0c4
Modificáronse 1 ficheiros con 22 adicións e 1 borrados
  1. 22 1
      src/network.rs

+ 22 - 1
src/network.rs

@@ -675,7 +675,7 @@ mod tests {
         eprintln!("Many requests test took {:?}", now.elapsed());
     }
 
-    // Typical request takes about 80ms.
+    // A typical request takes about 80ms.
     #[cfg(feature = "tracing")]
     #[test]
     fn test_tracing() -> Result<()> {
@@ -699,4 +699,25 @@ mod tests {
 
         Ok(())
     }
+
+    #[cfg(feature = "tracing")]
+    #[test]
+    #[ignore = "Large tests that runs for seconds"]
+    fn test_dispatch_delay() -> Result<()> {
+        let (_, client) = make_network_and_client();
+        const ROUND: usize = 100_000;
+
+        let mut dispatch_delay = 0;
+        for _ in 0..ROUND {
+            let (response, trace) = futures::executor::block_on(
+                client.trace_rpc(JunkRpcs::Echo.name(), RequestMessage::new()),
+            );
+            assert!(response.is_ok());
+            dispatch_delay += (trace.response - trace.assemble).as_nanos();
+        }
+        let avg_ms = (dispatch_delay as f64) / (ROUND as f64 * 1000.0);
+        eprintln!("The average RPC delay is {} ms", avg_ms);
+
+        Ok(())
+    }
 }