tangled
alpha
login
or
join now
ptr.pet
/
nsid-tracker
3
fork
atom
tracks lexicons and how many times they appeared on the jetstream
3
fork
atom
overview
issues
pulls
pipelines
feat(server): use ahash brrr
ptr.pet
7 months ago
78fdb32d
9da170a1
verified
This commit was signed with the committer's
known signature
.
ptr.pet
SSH Key Fingerprint:
SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw=
+45
-9
4 changed files
expand all
collapse all
unified
split
server
Cargo.lock
Cargo.toml
src
api.rs
db
mod.rs
+35
server/Cargo.lock
···
18
18
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
19
19
20
20
[[package]]
21
21
+
name = "ahash"
22
22
+
version = "0.8.12"
23
23
+
source = "registry+https://github.com/rust-lang/crates.io-index"
24
24
+
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
25
25
+
dependencies = [
26
26
+
"cfg-if",
27
27
+
"getrandom 0.3.3",
28
28
+
"once_cell",
29
29
+
"serde",
30
30
+
"version_check",
31
31
+
"zerocopy",
32
32
+
]
33
33
+
34
34
+
[[package]]
21
35
name = "aho-corasick"
22
36
version = "1.1.3"
23
37
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1558
1572
name = "server"
1559
1573
version = "0.1.0"
1560
1574
dependencies = [
1575
1575
+
"ahash",
1561
1576
"anyhow",
1562
1577
"arc-swap",
1563
1578
"async-trait",
···
2392
2407
version = "0.8.15"
2393
2408
source = "registry+https://github.com/rust-lang/crates.io-index"
2394
2409
checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3"
2410
2410
+
2411
2411
+
[[package]]
2412
2412
+
name = "zerocopy"
2413
2413
+
version = "0.8.26"
2414
2414
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2415
2415
+
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
2416
2416
+
dependencies = [
2417
2417
+
"zerocopy-derive",
2418
2418
+
]
2419
2419
+
2420
2420
+
[[package]]
2421
2421
+
name = "zerocopy-derive"
2422
2422
+
version = "0.8.26"
2423
2423
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2424
2424
+
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
2425
2425
+
dependencies = [
2426
2426
+
"proc-macro2",
2427
2427
+
"quote",
2428
2428
+
"syn",
2429
2429
+
]
2395
2430
2396
2431
[[package]]
2397
2432
name = "zeroize"
+1
server/Cargo.toml
···
32
32
rclite = "0.2.7"
33
33
snmalloc-rs = "0.3.8"
34
34
arc-swap = "1.7.1"
35
35
+
ahash = { version = "0.8.12", features = ["serde"] }
+4
-4
server/src/api.rs
···
1
1
use std::{
2
2
-
collections::HashMap,
3
2
fmt::Display,
4
3
net::SocketAddr,
5
4
ops::{Bound, Deref, RangeBounds},
6
5
time::Duration,
7
6
};
8
7
8
8
+
use ahash::AHashMap;
9
9
use anyhow::anyhow;
10
10
use axum::{
11
11
Json, Router,
···
117
117
#[derive(Serialize)]
118
118
struct Events {
119
119
per_second: usize,
120
120
-
events: HashMap<SmolStr, NsidCount>,
120
120
+
events: AHashMap<SmolStr, NsidCount>,
121
121
}
122
122
123
123
async fn events(db: State<Arc<Db>>) -> AppResult<Json<Events>> {
124
124
-
let mut events = HashMap::new();
124
124
+
let mut events = AHashMap::new();
125
125
for result in db.get_counts() {
126
126
let (nsid, counts) = result?;
127
127
events.insert(
···
200
200
(async move {
201
201
let mut listener = db.new_listener();
202
202
let mut data = Events {
203
203
-
events: HashMap::<SmolStr, NsidCount>::with_capacity(10),
203
203
+
events: AHashMap::<SmolStr, NsidCount>::with_capacity(10),
204
204
per_second: 0,
205
205
};
206
206
let mut updates = 0;
+5
-5
server/src/db/mod.rs
···
1
1
use std::{
2
2
-
collections::{HashMap, HashSet},
3
2
fmt::Debug,
4
3
io::Cursor,
5
4
ops::{Bound, Deref, RangeBounds},
···
8
7
u64,
9
8
};
10
9
10
10
+
use ahash::{AHashMap, AHashSet};
11
11
use byteview::StrView;
12
12
use fjall::{Keyspace, Partition, PartitionCreateOptions};
13
13
use itertools::{Either, Itertools};
···
72
72
}
73
73
74
74
pub struct DbInfo {
75
75
-
pub nsids: HashMap<SmolStr, Vec<usize>>,
75
75
+
pub nsids: AHashMap<SmolStr, Vec<usize>>,
76
76
pub disk_size: u64,
77
77
}
78
78
···
114
114
pub cfg: DbConfig,
115
115
pub ks: Keyspace,
116
116
counts: Partition,
117
117
-
hits: scc::HashIndex<SmolStr, Arc<LexiconHandle>>,
117
117
+
hits: scc::HashIndex<SmolStr, Arc<LexiconHandle>, ahash::RandomState>,
118
118
sync_pool: threadpool::ThreadPool,
119
119
event_broadcaster: broadcast::Sender<(SmolStr, NsidCounts)>,
120
120
eps: RateTracker<100>, // 100 millis buckets
···
167
167
// prepare all the data
168
168
let nsids_len = self.hits.len();
169
169
let mut data = Vec::with_capacity(nsids_len);
170
170
-
let mut nsids = HashSet::with_capacity(nsids_len);
170
170
+
let mut nsids = AHashSet::with_capacity(nsids_len);
171
171
let _guard = scc::ebr::Guard::new();
172
172
for (nsid, handle) in self.hits.iter(&_guard) {
173
173
let mut nsid_data = Vec::with_capacity(2);
···
370
370
}
371
371
372
372
pub fn info(&self) -> AppResult<DbInfo> {
373
373
-
let mut nsids = HashMap::new();
373
373
+
let mut nsids = AHashMap::new();
374
374
for nsid in self.get_nsids() {
375
375
let Some(handle) = self.get_handle(&nsid) else {
376
376
continue;