rustque/
lib.rs

1
2//!
3//! rustque is a fast local on disk data que, it can que Vec<u8> and can be best customized to your hardware.
4//! 
5//! rustque works on a principal of assembly lines passing on flume messeges to diffrent worker modules, when you initiate rustque it results into the first message pass in the assembly line this que handler can be cloned for async writes to the que on disk level depending on the os and hardware features disk writes are async too, disk files are distributed into empty and filled sections on a new que entry one disk worker locks a empty space and writes to it this locking mechnism allows us to spawn multiple disk workers which can read and write from the same file simultaniously. 
6//! 
7//! 
8//! sample code 
9//! ```
10//! use rustque::{Que,Config};
11//!
12//! #[tokio::main]
13//! async fn main(){
14//!
15//!     //---------------------------
16//!     //initiate que
17//!     //---------------------------
18//!     let mut que:Que;
19//!     match Que::new(Config::new(
20//!         vec![
21//!             "D://workstation/expo/rust/rust_store/test/rustque/que1.rustque".to_string(),
22//!             "D://workstation/expo/rust/rust_store/test/rustque/que2.rustque".to_string(),
23//!             "D://workstation/expo/rust/rust_store/test/rustque/que3.rustque".to_string()
24//!         ],                  //que files
25//!         500000000,          //min que size on disk in bytes
26//!         5000000,            //expand file on disk by this many bytes when full in bytes
27//!         100                 //no of disk workers per que file
28//!     )).await{
29//!         Ok(v)=>{
30//!             que = v;
31//!             println!("que initiated : {:?}",hold.elapsed());
32//!         },
33//!         Err(e)=>{
34//!             println!("!!! failed-que::new => {:?}",e);
35//!             return;
36//!         }
37//!     }
38//!
39//!     //---------------------------
40//!     //write items to the que
41//!     //---------------------------
42//!     if true {
43//!         match que.add(vec![1,2,3]).await{
44//!             Ok(mut que_response)=>{
45//!                 collect.push(async move{
46//!                     que_response.check().await
47//!                 });
48//!             },
49//!             Err(_e)=>{
50//!                 println!("!!! failed-que-add : {:?}",_e);
51//!             }
52//!         }
53//!     }
54//!
55//!     //---------------------------
56//!     // please enable get, remove and reset
57//!     // functions once at a time or write 
58//!     // que items for each of them
59//!     //---------------------------
60//!
61//!     //---------------------------
62//!     //get qued item from que
63//!     //---------------------------
64//!     if true{
65//!         match que.next().await{
66//!             Ok(mut next_response)=>{
67//!                 let _quer_resp = next_response.check().await;
68//!                 if !_quer_resp {break;}
69//!                 match next_response.data().await{
70//!                     Some((value,pointer))=>{
71//!                         println!("value : {:?}",value);
72//!                     },
73//!                     None=>{}
74//!                 }
75//!             },
76//!             Err(_e)=>{
77//!                 println!("!!! failed-que-get : {:?}",_e);
78//!             }
79//!         }
80//!     }
81//!
82//!     //---------------------------
83//!     //remove item from que
84//!     //---------------------------
85//!     if true{
86//!         match que.next().await{
87//!             Ok(mut next_response)=>{
88//!                 if next_response.check().await {
89//!                     match next_response.data().await{
90//!                         Some((_value,pointer))=>{
91//!                             match que.remove(pointer).await{
92//!                                 Ok(mut remove_response)=>{
93//!                                     let remove_resp = remove_response.check().await;
94//!                                     println!("remove resp : {:?}",remove_resp);
95//!                                 },
96//!                                 Err(_e)=>{
97//!                                     println!("!!! failed-que-remove : {:?}",_e);
98//!                                 }
99//!                             }
100//!                         },
101//!                         None=>{}
102//!                     }
103//!                 }
104//!             },
105//!             Err(_e)=>{
106//!                 println!("!!! failed-que-get : {:?}",_e);
107//!             }
108//!         }
109//!     }
110//!
111//!     //---------------------------
112//!     //reset item in que
113//!     //---------------------------
114//!     if true{
115//!         match que.next().await{
116//!             Ok(mut next_response)=>{
117//!                 if next_response.check().await {
118//!                     match next_response.data().await{
119//!                         Some((_value,pointer))=>{
120//!                             match que.reset(pointer).await{
121//!                                 Ok(mut reset_response)=>{
122//!                                     let reset_resp = reset_response.check().await;
123//!                                     println!("reset resp : {:?}",reset_resp);
124//!                                 },
125//!                                 Err(_e)=>{
126//!                                     println!("!!! failed-que-reset : {:?}",_e);
127//!                                 }
128//!                             }
129//!                         },
130//!                         None=>{}
131//!                     }
132//!                 }
133//!             },
134//!             Err(_e)=>{
135//!                 println!("!!! failed-que-get : {:?}",_e);
136//!             }
137//!         }
138//!     }
139//!
140//! }
141//! ```
142//! Bechmarking is a feature that needs to be enabled in cargo.toml this features provides tools to bechmark best settings for your hardware you need to provide multiple settings to test from and results will be written on the file you specify.
143//! 
144//! ```
145//! [dependencies]
146//! //enable bechmark feature in cargo.toml
147//! rustque = {version="1.0.4", features=["benchmark"]}
148//! ```
149//! 
150//! ```
151//! use rustque::bechmark::{BenchmarkBuilder,Benchmark};
152//! 
153//! #[tokio::main]
154//! async fn main(){
155//!
156//!     //---------------------------
157//!     //init benchmark builder
158//!     //---------------------------
159//!     let mut build = BenchmarkBuilder::new(
160//!         "D://workstation/expo/rust/rust_store/test/rustque/bechmark_8.txt".to_string()
161//!     );
162//!
163//!     //---------------------------
164//!    //add a benchmark
165//!     //---------------------------
166//!     build.add(Benchmark{
167//!         no_of_writers:10,
168//!         no_of_writes:5000,
169//!         map_files:vec![
170//!             "D://workstation/expo/rust/rust_store/test/rustque/que1.rustque".to_string(),
171//!             "D://workstation/expo/rust/rust_store/test/rustque/que2.rustque".to_string(),
172//!             "D://workstation/expo/rust/rust_store/test/rustque/que3.rustque".to_string(),
173//!         ],
174//!         write_size:256,
175//!         min_que_size:10000000,
176//!         expansion_size:5000000,
177//!         no_of_disk_workers:10
178//!     });
179//!
180//!     //---------------------------
181//!     //run the benchmarks
182//!     //---------------------------
183//!     build.run().await;
184//!
185//! }
186//! ```
187
188mod io;
189mod config;
190mod que;
191mod map;
192mod disk;
193mod workers;
194mod locator;
195mod response;
196
197#[cfg(feature = "benchmark")]
198pub mod benchmark;
199
200pub use config::Config;
201pub use que::Que;
202pub use workers::Pointer;
203pub use response::QueResponse;