|
1 | 1 | #[macro_use]
|
2 | 2 | mod macros;
|
3 | 3 |
|
4 |
| -use std::{time::{Duration, Instant}, collections::HashMap, sync::Mutex}; |
| 4 | +use std::time::{Duration, Instant}; |
5 | 5 | use self::macros::MetricFromOpts;
|
6 | 6 | use crate::db::Pool;
|
7 | 7 | use crate::BuildQueue;
|
8 | 8 | use failure::Error;
|
9 | 9 | use prometheus::proto::MetricFamily;
|
| 10 | +use dashmap::DashMap; |
10 | 11 |
|
11 | 12 | load_metric_type!(IntGauge as single);
|
12 | 13 | load_metric_type!(IntCounter as single);
|
@@ -76,30 +77,26 @@ metrics! {
|
76 | 77 | namespace: "docsrs",
|
77 | 78 | }
|
78 | 79 |
|
79 |
| -#[derive(Debug)] |
| 80 | +#[derive(Debug, Default)] |
80 | 81 | pub(crate) struct RecentReleases {
|
81 |
| - krates: Mutex<HashMap<String, Instant>>, |
82 |
| - versions: Mutex<HashMap<String, Instant>>, |
83 |
| - platforms: Mutex<HashMap<String, Instant>>, |
| 82 | + krates: DashMap<String, Instant>, |
| 83 | + versions: DashMap<String, Instant>, |
| 84 | + platforms: DashMap<String, Instant>, |
84 | 85 | }
|
85 | 86 |
|
86 | 87 | impl RecentReleases {
|
87 | 88 | pub(crate) fn new() -> Self {
|
88 |
| - Self { |
89 |
| - krates: Mutex::new(HashMap::new()), |
90 |
| - versions: Mutex::new(HashMap::new()), |
91 |
| - platforms: Mutex::new(HashMap::new()), |
92 |
| - } |
| 89 | + Self::default() |
93 | 90 | }
|
94 | 91 |
|
95 | 92 | pub(crate) fn record(&self, krate: &str, version: &str, target: &str) {
|
96 |
| - self.krates.lock().unwrap().insert(krate.to_owned(), Instant::now()); |
97 |
| - self.versions.lock().unwrap().insert(format!("{}/{}", krate, version), Instant::now()); |
98 |
| - self.platforms.lock().unwrap().insert(format!("{}/{}/{}", krate, version, target), Instant::now()); |
| 93 | + self.krates.insert(krate.to_owned(), Instant::now()); |
| 94 | + self.versions.insert(format!("{}/{}", krate, version), Instant::now()); |
| 95 | + self.platforms.insert(format!("{}/{}/{}", krate, version, target), Instant::now()); |
99 | 96 | }
|
100 | 97 |
|
101 | 98 | pub(crate) fn gather(&self, metrics: &Metrics) {
|
102 |
| - fn inner(map: &mut HashMap<String, Instant>, metric: &IntGaugeVec) { |
| 99 | + fn inner(map: &DashMap<String, Instant>, metric: &IntGaugeVec) { |
103 | 100 | let mut hour_count = 0;
|
104 | 101 | let mut half_hour_count = 0;
|
105 | 102 | let mut five_minute_count = 0;
|
@@ -133,9 +130,9 @@ impl RecentReleases {
|
133 | 130 | .set(five_minute_count);
|
134 | 131 | }
|
135 | 132 |
|
136 |
| - inner(&mut *self.krates.lock().unwrap(), &metrics.recent_krates); |
137 |
| - inner(&mut *self.versions.lock().unwrap(), &metrics.recent_versions); |
138 |
| - inner(&mut *self.platforms.lock().unwrap(), &metrics.recent_platforms); |
| 133 | + inner(&self.krates, &metrics.recent_krates); |
| 134 | + inner(&self.versions, &metrics.recent_versions); |
| 135 | + inner(&self.platforms, &metrics.recent_platforms); |
139 | 136 | }
|
140 | 137 | }
|
141 | 138 |
|
|
0 commit comments