1+ mod support;
2+
13use criterion:: { black_box, criterion_group, criterion_main, BenchmarkId , Criterion } ;
24use janus:: {
35 execution:: historical_executor:: HistoricalExecutor ,
46 parsing:: janusql_parser:: { SourceKind , WindowDefinition , WindowType } ,
57 querying:: oxigraph_adapter:: OxigraphAdapter ,
6- storage:: { segmented_storage:: StreamingSegmentedStorage , util:: StreamingConfig } ,
7- } ;
8- use std:: sync:: {
9- atomic:: { AtomicU64 , Ordering } ,
10- Arc ,
8+ storage:: segmented_storage:: StreamingSegmentedStorage ,
119} ;
12- use std:: time:: { SystemTime , UNIX_EPOCH } ;
13-
14- static COUNTER : AtomicU64 = AtomicU64 :: new ( 0 ) ;
15-
16- fn unique_config ( ) -> StreamingConfig {
17- let id = COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
18- let ts = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_nanos ( ) ;
19- StreamingConfig {
20- segment_base_path : format ! ( "/tmp/janus_bench_sliding_{}_{}" , ts, id) ,
21- max_batch_events : 1_000_000 ,
22- max_batch_age_seconds : 3600 ,
23- max_batch_bytes : 1_000_000_000 ,
24- sparse_interval : 64 ,
25- entries_per_index_block : 256 ,
26- }
27- }
10+ use std:: sync:: Arc ;
11+ use support:: { populate_storage, recent_base_timestamp, unique_config, GRAPH_URI } ;
2812
2913// Window config: OFFSET=10_000ms, RANGE=2_000ms, SLIDE=1_000ms
3014// SlidingWindowIterator scans [now-10000, now] with 8 overlapping windows.
@@ -36,25 +20,14 @@ const DATA_START_BEFORE_NOW_MS: u64 = 8_000;
3620const DATA_SPAN_MS : u64 = 6_000 ;
3721
3822fn setup ( n : usize ) -> ( Arc < StreamingSegmentedStorage > , WindowDefinition ) {
39- let now = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_millis ( ) as u64 ;
40- let storage = StreamingSegmentedStorage :: new ( unique_config ( ) ) . unwrap ( ) ;
41- let n64 = n as u64 ;
42- for i in 0 ..n64 {
43- let ts = now - DATA_START_BEFORE_NOW_MS + i * DATA_SPAN_MS / n64. max ( 1 ) ;
44- storage
45- . write_rdf (
46- ts,
47- & format ! ( "http://example.org/sensor{}" , i % 5 ) ,
48- "http://saref.etsi.org/core/hasValue" ,
49- & format ! ( "{}" , 20 + ( i % 10 ) ) ,
50- "http://example.org/graph" ,
51- )
52- . unwrap ( ) ;
53- }
23+ let start_ts = recent_base_timestamp ( DATA_START_BEFORE_NOW_MS ) ;
24+ let storage = StreamingSegmentedStorage :: new ( unique_config ( "historical_sliding" ) ) . unwrap ( ) ;
25+ let step_ms = ( DATA_SPAN_MS / n. max ( 1 ) as u64 ) . max ( 1 ) ;
26+ populate_storage ( & storage, n, start_ts, step_ms, GRAPH_URI ) ;
5427 let window = WindowDefinition {
5528 window_name : "w" . to_string ( ) ,
5629 source_kind : SourceKind :: Stream ,
57- stream_name : "http://example.org/stream" . to_string ( ) ,
30+ stream_name : GRAPH_URI . to_string ( ) ,
5831 width : RANGE_MS ,
5932 slide : SLIDE_MS ,
6033 offset : Some ( OFFSET_MS ) ,
@@ -65,7 +38,15 @@ fn setup(n: usize) -> (Arc<StreamingSegmentedStorage>, WindowDefinition) {
6538 ( Arc :: new ( storage) , window)
6639}
6740
68- const SPARQL : & str = "SELECT ?s ?p ?o WHERE { ?s ?p ?o }" ;
41+ const SPARQL : & str = r#"
42+ PREFIX ex: <http://example.org/>
43+ SELECT ?sensor ?temp
44+ WHERE {
45+ GRAPH ex:graph1 {
46+ ?sensor ex:temperature ?temp .
47+ }
48+ }
49+ "# ;
6950
7051fn historical_sliding ( c : & mut Criterion ) {
7152 let mut group = c. benchmark_group ( "historical/sliding_window" ) ;
0 commit comments