@@ -27,7 +27,8 @@ use netipc::protocol::{
2727use netipc:: service:: cgroups:: { CgroupsClient , ClientConfig as TypedClientConfig } ;
2828#[ cfg( windows) ]
2929use netipc:: service:: raw:: {
30- increment_dispatch, snapshot_dispatch, CgroupsCacheItem , DispatchHandler , ManagedServer ,
30+ increment_dispatch, snapshot_dispatch, CgroupsCache , CgroupsCacheItem , DispatchHandler ,
31+ ManagedServer ,
3132} ;
3233#[ cfg( windows) ]
3334use netipc:: transport:: win_shm:: { WinShmContext , PROFILE_HYBRID as WIN_SHM_PROFILE_HYBRID } ;
@@ -1758,20 +1759,6 @@ fn run_pipeline_batch_client(
17581759
17591760#[ cfg( windows) ]
17601761fn run_lookup_bench ( duration_sec : u32 ) -> i32 {
1761- #[ derive( Clone , Copy , Default ) ]
1762- struct Bucket {
1763- index : usize ,
1764- used : bool ,
1765- }
1766-
1767- fn hash_name ( name : & str ) -> u32 {
1768- let mut h: u32 = 5381 ;
1769- for b in name. as_bytes ( ) {
1770- h = ( ( h << 5 ) . wrapping_add ( h) ) . wrapping_add ( * b as u32 ) ;
1771- }
1772- h
1773- }
1774-
17751762 let items: Vec < CgroupsCacheItem > = ( 0 ..16 )
17761763 . map ( |i| CgroupsCacheItem {
17771764 hash : 1000 + i,
@@ -1782,33 +1769,30 @@ fn run_lookup_bench(duration_sec: u32) -> i32 {
17821769 } )
17831770 . collect ( ) ;
17841771
1785- let mut lookup_index = vec ! [ Bucket :: default ( ) ; 32 ] ;
1786- let mask = ( lookup_index. len ( ) - 1 ) as u32 ;
1787- for ( idx, item) in items. iter ( ) . enumerate ( ) {
1788- let mut slot = ( item. hash ^ hash_name ( & item. name ) ) & mask;
1789- while lookup_index[ slot as usize ] . used {
1790- slot = ( slot + 1 ) & mask;
1791- }
1792- lookup_index[ slot as usize ] = Bucket {
1793- index : idx,
1794- used : true ,
1795- } ;
1796- }
1772+ let cache = CgroupsCache :: new (
1773+ "." ,
1774+ "bench_lookup" ,
1775+ ClientConfig {
1776+ supported_profiles : PROFILE_BASELINE ,
1777+ preferred_profiles : 0 ,
1778+ max_request_payload_bytes : 0 ,
1779+ max_request_batch_items : 1 ,
1780+ max_response_payload_bytes : RESPONSE_BUF_SIZE as u32 ,
1781+ max_response_batch_items : 1 ,
1782+ auth_token : AUTH_TOKEN ,
1783+ packet_size : 0 ,
1784+ } ,
1785+ ) ;
1786+ cache. seed_for_tests ( items. clone ( ) , 1 , 1 ) ;
17971787
17981788 let mut lookups: u64 = 0 ;
17991789 let mut hits: u64 = 0 ;
18001790
18011791 let warmup_deadline = TickDeadline :: new ( LOOKUP_WARMUP_SEC ) ;
18021792 while !warmup_deadline. expired ( ) {
1793+ let guard = cache. read_lock ( ) ;
18031794 for item in & items {
1804- let mut slot = ( item. hash ^ hash_name ( & item. name ) ) & mask;
1805- while lookup_index[ slot as usize ] . used {
1806- let bucket_item = & items[ lookup_index[ slot as usize ] . index ] ;
1807- if bucket_item. hash == item. hash && bucket_item. name == item. name {
1808- break ;
1809- }
1810- slot = ( slot + 1 ) & mask;
1811- }
1795+ let _ = guard. get ( item. hash , & item. name ) ;
18121796 }
18131797 }
18141798
@@ -1817,18 +1801,9 @@ fn run_lookup_bench(duration_sec: u32) -> i32 {
18171801 let tick_deadline = TickDeadline :: new ( duration_sec) ;
18181802
18191803 while !tick_deadline. expired ( ) {
1804+ let guard = cache. read_lock ( ) ;
18201805 for item in & items {
1821- let mut slot = ( item. hash ^ hash_name ( & item. name ) ) & mask;
1822- let mut found = false ;
1823- while lookup_index[ slot as usize ] . used {
1824- let bucket_item = & items[ lookup_index[ slot as usize ] . index ] ;
1825- if bucket_item. hash == item. hash && bucket_item. name == item. name {
1826- found = true ;
1827- break ;
1828- }
1829- slot = ( slot + 1 ) & mask;
1830- }
1831- if found {
1806+ if guard. get ( item. hash , & item. name ) . is_some ( ) {
18321807 hits += 1 ;
18331808 }
18341809 lookups += 1 ;
0 commit comments