Prechádzať zdrojové kódy

使用instant测试性能

skyfffire 1 rok pred
rodič
commit
324be6711c

+ 19 - 5
exchanges/src/response_base.rs

@@ -1,3 +1,5 @@
+use std::time::Instant;
+
 /**交易所返回数据处理之后,同意保存格式,为了内部其他接口调用*/
 #[derive(Debug, Clone)]
 pub struct ResponseData {
@@ -6,14 +8,25 @@ pub struct ResponseData {
     pub message: String,
     pub channel: String,
     pub data: String,
-    pub time: i64,       //数据接受的时间
-    pub reach_time: i64, //远程数据时间 弃用
-    pub data_type: String // 數據類型, 例如 bybit 深度信息:snapshot(全量),delta(增量)
+    pub res_time: Instant,      // 数据接收的ins
+    pub time: i64,              // 数据接受的时间
+    pub reach_time: i64,        // 远程数据时间 弃用
+    pub data_type: String       // 數據類型, 例如 bybit 深度信息:snapshot(全量),delta(增量)
 }
 
 impl ResponseData {
     pub fn new(label: String, code: String, message: String, data: String) -> ResponseData {
-        ResponseData { label, code, message, data, channel: "".to_string(), time: 0, reach_time: 0 , data_type: String::new()}
+        ResponseData {
+            label,
+            code,
+            message,
+            data,
+            channel: "".to_string(),
+            time: 0,
+            reach_time: 0,
+            data_type: String::new(),
+            res_time: Instant::now(),
+        }
     }
     pub fn error(label: String, message: String) -> ResponseData {
         ResponseData {
@@ -24,7 +37,8 @@ impl ResponseData {
             channel: "".to_string(),
             time: 0,
             reach_time: 0,
-            data_type: String::new()
+            data_type: String::new(),
+            res_time: Instant::now(),
         }
     }
 

+ 3 - 2
exchanges/src/socket_tool.rs

@@ -1,7 +1,7 @@
 use std::net::{IpAddr, Ipv4Addr, SocketAddr};
 use std::sync::Arc;
 use std::sync::atomic::{AtomicBool, Ordering};
-use std::time::Duration;
+use std::time::{Duration, Instant};
 
 use chrono::Utc;
 use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
@@ -84,7 +84,8 @@ impl AbstractWsMode {
 
                     if code == "200" {
                         let mut data_c = data.clone();
-                        data_c.time = chrono::Utc::now().timestamp_micros();
+                        data_c.res_time = Instant::now();
+
                         handle_function(data_c).await;
                     }
 

+ 1 - 4
strategy/src/binance_usdt_swap.rs

@@ -36,11 +36,8 @@ pub(crate) async fn reference_binance_swap_run(is_shutdown_arc: Arc<AtomicBool>,
         let fun = move |data: ResponseData| {
             // 在 async 块之前克隆 Arc
             // let core_arc_clone = core_arc_clone.clone();
-            let mut trace_stack = TraceStack::default();
-            trace_stack.on_after_network(data.time);
             async move {
-                trace_stack.on_after_span_line();
-                info!("bian: {}", trace_stack.to_string());
+                info!("gate: {:.2?}", data.res_time.elapsed());
                 // 使用克隆后的 Arc,避免 move 语义
                 // on_data(core_arc_clone,
                 //         &mut update_flag_u,

+ 1 - 4
strategy/src/gate_swap.rs

@@ -74,17 +74,14 @@ pub async fn gate_swap_run(is_shutdown_arc: Arc<AtomicBool>,
             // 在 async 块之前克隆 Arc
             // let mul = multiplier.clone();
             // let rs = run_symbol.clone();
-            let mut trace_stack = TraceStack::default();
-            trace_stack.on_after_network(data.time);
 
             async move {
-                trace_stack.on_after_span_line();
                 // // 使用克隆后的 Arc,避免 move 语义
                 // trace_stack.on_before_unlock_core();
                 // let _ = core_arc_cc.lock().await;
                 // trace_stack.on_before_core();
 
-                info!("gate: {}", trace_stack.to_string());
+                info!("gate: {:.2?}", data.res_time.elapsed());
 
                 // on_data(core_arc_cc,
                 //         &mut update_flag_u,