Skip to content

Commit 7a4bfa1

Browse files
committed
Hmm
1 parent ba2fcfe commit 7a4bfa1

File tree

4 files changed

+27
-40
lines changed

4 files changed

+27
-40
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/corro-types/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ sqlite-pool = { path = "../sqlite-pool" }
4646
sqlite3-parser = { workspace = true }
4747
tempfile = { workspace = true }
4848
thiserror = { workspace = true }
49-
thread_local = "1.1"
5049
time = { workspace = true }
5150
tokio = { workspace = true }
5251
tokio-util = { workspace = true }

crates/corro-types/src/sqlite.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,35 @@ use rusqlite::{
1414
use sqlite_pool::{Committable, SqliteConn};
1515
use std::rc::Rc;
1616
use tempfile::TempDir;
17-
use thread_local::ThreadLocal;
1817
use tracing::{error, info, trace, warn};
1918

2019
use crate::vtab::unnest::UnnestTab;
2120

2221
pub type SqlitePool = sqlite_pool::Pool<CrConn>;
2322
pub type SqlitePoolError = sqlite_pool::PoolError;
23+
use lazy_static::lazy_static;
2424

25-
// Global registry for thread-local query stats
26-
type QueryStatsMap = Mutex<HashMap<String, u128>>;
27-
static QUERY_STATS_REGISTRY: Lazy<Arc<ThreadLocal<QueryStatsMap>>> =
28-
Lazy::new(|| Arc::new(ThreadLocal::new()));
29-
30-
pub fn print_aggregated_query_stats() {
31-
print_aggregated_stats(&QUERY_STATS_REGISTRY);
25+
// Global registry for query stats - single shared HashMap
26+
lazy_static! {
27+
static ref QUERY_STATS: Mutex<HashMap<String, u128>> =
28+
Mutex::new(HashMap::new());
3229
}
33-
34-
fn print_aggregated_stats(registry: &Arc<ThreadLocal<QueryStatsMap>>) {
35-
let mut aggregated: HashMap<String, u128> = HashMap::new();
36-
37-
// Collect and reset stats from all threads
38-
for stats in registry.iter() {
39-
let mut stats = stats.lock();
40-
for (query, total_nanos) in stats.iter() {
41-
*aggregated.entry(query.clone()).or_insert(0) += total_nanos;
42-
}
43-
stats.clear(); // Reset for next interval
44-
}
45-
46-
if !aggregated.is_empty() {
30+
pub fn print_aggregated_query_stats() {
31+
let mut stats = QUERY_STATS.lock();
32+
33+
if !stats.is_empty() {
4734
info!("=== Query Statistics (last 10s) ===");
48-
let mut sorted: Vec<_> = aggregated.iter().collect();
35+
let mut sorted: Vec<_> = stats.iter().collect();
4936
sorted.sort_by(|a, b| b.1.cmp(a.1)); // Sort by total time descending
5037

5138
for (query, total_nanos) in sorted.iter().take(10) {
5239
let total_ms = *total_nanos / 1_000_000;
5340
info!(" {total_ms}ms total: {query}");
5441
}
5542
info!("===================================");
43+
44+
// Clear stats for next interval
45+
stats.clear();
5646
}
5747
}
5848

@@ -115,10 +105,10 @@ pub fn rusqlite_to_crsqlite(mut conn: rusqlite::Connection) -> rusqlite::Result<
115105
let dur = duration.as_nanos();
116106
let sql = stmt_ref.sql().to_string();
117107

118-
// Get or create thread-local stats
119-
let stats = QUERY_STATS_REGISTRY.get_or(|| Mutex::new(HashMap::new()));
120-
let mut stats = stats.lock();
108+
// Update shared stats
109+
let mut stats = QUERY_STATS.lock();
121110
*stats.entry(sql.clone()).or_insert(0) += dur;
111+
drop(stats); // Release lock quickly
122112

123113
if duration >= SLOW_THRESHOLD {
124114
warn!("SLOW query {duration:?} => {}", sql);

examples/fly/config.toml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
[db]
2-
path = "/var/lib/corrosion/state.db"
3-
schema_paths = ["/etc/corrosion/schemas"]
4-
2+
path = "/tmp/corrosion.db"
3+
schema_paths = ["/tmp/schema"]
4+
55
[gossip]
6-
# addr and bootstrap for Fly.io deployment example are written
7-
# on startup by entrypoint script
8-
plaintext = true # Cryptography and authz are handled by Fly.io private networking
9-
max_mtu = 1372 # For Fly.io private network
10-
disable_gso = true # For Fly.io private network
6+
addr = "[::]:8787"
7+
bootstrap = []
8+
plaintext = true
119

1210
[api]
13-
addr = "[::]:8080" # Must be available on IPv6 for Fly.io private network
11+
addr = "127.0.0.1:8080"
1412

1513
[admin]
16-
path = "/app/admin.sock"
14+
path = "/tmp/corrosion-admin.sock"
1715

1816
[telemetry]
19-
prometheus.addr = "0.0.0.0:9090"
17+
prometheus.addr = "127.0.0.1:9090"
2018

2119
[log]
22-
colors = false
20+
format = "json"
21+

0 commit comments

Comments
 (0)