-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathredis_benchmark.rs
More file actions
61 lines (54 loc) · 2.02 KB
/
redis_benchmark.rs
File metadata and controls
61 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use log::{info};
use tokio;
use credit_card::CreditCard;
use data_vault::{RedisDataVault, DataVault};
use std::vec;
use std::time::{Instant};
use std::sync::Arc;
use data_vault::encryption::AesGcmSivEncryption;
use data_vault::tokenizer::Blake3Tokenizer;
#[tokio::main(flavor = "multi_thread", worker_threads = 24)]
async fn main() {
env_logger::init();
let mut token_futures = vec::Vec::new();
let mut result_futures = vec::Vec::new();
let redis_vault = RedisDataVault::<AesGcmSivEncryption, Blake3Tokenizer>::new().unwrap();
let vault = Arc::new(redis_vault);
let cc = Arc::new(CreditCard {
number: "4111111111111111".to_string(),
cardholder_name: "Graydon Hoare".to_string(),
expiration_month: "01".to_string(),
expiration_year: "2023".to_string(),
brand: None,
security_code: None
});
let to_store:i32 = 100000;
println!("start");
let start_time = Instant::now();
for _ in 0..to_store {
let vault = vault.clone();
let cc = Arc::clone(&cc);
token_futures.push(
tokio::task::spawn(async move {
vault.store_credit_card(&cc).await
})
);
}
let results = futures::future::join_all(token_futures).await;
let stored_time = Instant::now();
println!("tokenized and stored {} credit cards in {:?}", to_store, stored_time.duration_since(start_time));
for token_result in results {
let vault = vault.clone();
let token_result = token_result.unwrap();
let token = token_result.unwrap();
result_futures.push(
tokio::task::spawn(async move {
vault.retrieve_credit_card(&token).await
})
);
}
futures::future::join_all(result_futures).await;
let end_time = Instant::now();
println!("retrieved {} credit cards in {:?}", to_store, end_time.duration_since(stored_time));
println!("tokenized, stored, and retrieved {} credit cards in {:?}", to_store, end_time.duration_since(start_time));
}