This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client.sender = Some(client_sender); | |
clients.write().await.insert(id.clone(), client); | |
log::info!("[ws] client_connect : {} connected", id); | |
let locked = clients.write().await; | |
if let Some(v) = locked.get(&id) { | |
if let Some(sender) = &v.sender { | |
log::info!("[ws] client_msg : topic {:?}", v.topic); | |
twitter_stream(v.topic.clone(), sender.clone()).await; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (client_ws_sender, mut _client_ws_rcv) = ws.split(); | |
let (client_sender, client_rcv) = mpsc::unbounded_channel(); | |
let client_rcv = UnboundedReceiverStream::new(client_rcv); | |
tokio::task::spawn(client_rcv.forward(client_ws_sender).map(|result| { | |
if let Err(e) = result { | |
log::error!("Failed toerror sending websocket msg: {}", e); | |
} | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let register = warp::path("register"); | |
let register_routes = register | |
.and(warp::post()) | |
.and(warp::body::json()) | |
.and(with_clients(client_store.clone())) | |
.and_then(app::handlers::register_handler) | |
.or(register | |
.and(warp::delete()) | |
.and(warp::path::param()) | |
.and(with_clients(client_store.clone())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use crate::ClientStore; | |
use uuid::Uuid; | |
use warp::ws::Message; | |
use tokio::sync::{mpsc}; | |
use serde::{Deserialize, Serialize}; | |
#[derive(Debug, Clone)] | |
pub struct Client { | |
pub user_id: Uuid, | |
pub topic: String, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark 1: ./rust-velocity-limit | |
Time (mean ± σ): 13.0 ms ± 1.4 ms [User: 4.5 ms, System: 7.0 ms] | |
Range (min … max): 11.1 ms … 16.7 ms 155 runs | |
Benchmark 2: ./go-velocity-limit | |
Time (mean ± σ): 9.9 ms ± 0.8 ms [User: 11.7 ms, System: 6.3 ms] | |
Range (min … max): 8.9 ms … 13.3 ms 214 runs | |
Summary | |
'./go-velocity-limit' ran |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark 1: ./rust-velocity-limit | |
Time (mean ± σ): 7.3 ms ± 0.6 ms [User: 4.2 ms, System: 1.6 ms] | |
Range (min … max): 5.4 ms … 11.8 ms 234 runs | |
Benchmark 2: ./go-velocity-limit | |
Time (mean ± σ): 9.6 ms ± 0.5 ms [User: 11.5 ms, System: 6.1 ms] | |
Range (min … max): 8.8 ms … 11.6 ms 216 runs | |
Summary | |
'./rust-velocity-limit' ran |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
❯ cargo run -r | |
Finished release [optimized] target(s) in 0.17s | |
Running `target/release/rust-velocity-limit` | |
duration total execution time: 11.30037ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"id":"31808","customer_id":"511","accept":true} | |
{"id":"558","customer_id":"256","accept":false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"id":"1234","customer_id":"528","load_amount":"$3318.47","time":"2000-01-01T00:00:00Z"} | |
{"id":"5678","customer_id":"154","load_amount":"$1413.18","time":"2000-01-01T01:01:22Z"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let f = File::create(path).expect("Unable to create file"); | |
+let mut buf = BufWriter::new(f); | |
for line in &self.output{ | |
let serialized = serde_json::to_string(&line).unwrap(); | |
writeln!(&mut buf, "{}", serialized).unwrap(); | |
} |