Browse Source

Tune announcer performance

master
Natsu Kagami 1 year ago
parent
commit
5d6e537ac2
Signed by untrusted user: natsukagami <natsukagami@gmail.com> GPG Key ID: 73376E117CD20735
7 changed files with 15 additions and 3 deletions
  1. +2
    -0
      Cargo.lock
  2. +1
    -0
      youmubot-cf/Cargo.toml
  3. +3
    -0
      youmubot-cf/src/announcer.rs
  4. +1
    -1
      youmubot-osu/src/lib.rs
  5. +1
    -0
      youmubot-prelude/Cargo.toml
  6. +6
    -1
      youmubot-prelude/src/announcer.rs
  7. +1
    -1
      youmubot/src/main.rs

+ 2
- 0
Cargo.lock View File

@@ -1720,6 +1720,7 @@ dependencies = [
"Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"codeforces 0.1.0 (git+https://github.com/natsukagami/rust-codeforces-api)",
"crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1776,6 +1777,7 @@ dependencies = [
name = "youmubot-prelude"
version = "0.1.0"
dependencies = [
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",


+ 1
- 0
youmubot-cf/Cargo.toml View File

@@ -15,6 +15,7 @@ regex = "1"
lazy_static = "1"
rayon = "1"
chrono = { version = "0.4", features = ["serde"] }
crossbeam-channel = "0.4"

youmubot-prelude = { path = "../youmubot-prelude" }
youmubot-db = { path = "../youmubot-db" }

+ 3
- 0
youmubot-cf/src/announcer.rs View File

@@ -39,6 +39,8 @@ fn update_user(
user_id: UserId,
cfu: &mut CfUser,
) -> CommandResult {
// Ensure this takes 200ms
let after = crossbeam_channel::after(std::time::Duration::from_secs_f32(0.2));
let info = User::info(reqwest, &[cfu.handle.as_str()])?
.into_iter()
.next()
@@ -91,6 +93,7 @@ fn update_user(
}
}
}
after.recv().ok();

Ok(())
}

+ 1
- 1
youmubot-osu/src/lib.rs View File

@@ -41,7 +41,7 @@ impl Client {

fn build_request(&self, r: RequestBuilder) -> Result<Response, Error> {
let v = r.query(&[("k", &*self.key)]).build()?;
dbg!(v.url());
// dbg!(v.url());
Ok(self.client.execute(v)?)
}



+ 1
- 0
youmubot-prelude/Cargo.toml View File

@@ -12,3 +12,4 @@ youmubot-db = { path = "../youmubot-db" }
crossbeam-channel = "0.4"
reqwest = "0.10"
rayon = "1"
chrono = "0.4"

+ 6
- 1
youmubot-prelude/src/announcer.rs View File

@@ -1,4 +1,5 @@
use crate::{AppData, GetCloned};
use crossbeam_channel::after;
use rayon::prelude::*;
use serenity::{
framework::standard::{
@@ -153,12 +154,16 @@ impl AnnouncerHandler {
let keys = self.announcers.keys().cloned().collect::<Vec<_>>();
self.data.write().insert::<Self>(keys.clone());
spawn(move || loop {
eprintln!("{}: announcer started scanning", chrono::Utc::now());
let after_timer = after(cooldown);
for key in &keys {
eprintln!(" - scanning key `{}`", key);
if let Err(e) = self.announce(key) {
dbg!(e);
}
}
std::thread::sleep(cooldown);
eprintln!("{}: announcer finished scanning", chrono::Utc::now());
after_timer.recv().ok();
})
}
}


+ 1
- 1
youmubot/src/main.rs View File

@@ -98,7 +98,7 @@ fn main() {
println!("codeforces enabled.");

client.with_framework(fw);
announcers.scan(std::time::Duration::from_secs(300));
announcers.scan(std::time::Duration::from_secs(120));

println!("Starting...");
if let Err(v) = client.start() {


Loading…
Cancel
Save