async fn check_once(&self, first_run: bool) {
        let servers = &self.servers;
        if servers.is_empty() {
            return;
        }

        let mut vfut_tcp = Vec::with_capacity(servers.len());
        let mut vfut_udp = Vec::with_capacity(servers.len());

        for server in servers.iter() {
            let svr_cfg = server.server_config();

            if self.mode.enable_tcp() && Self::check_server_tcp_enabled(svr_cfg) {
                let checker = PingChecker {
                    server: server.clone(),
                    server_type: ServerType::Tcp,
                    context: self.context.clone(),
                    max_server_rtt: self.max_server_rtt,
                };
                vfut_tcp.push(checker.check_update_score());
            }

            if self.mode.enable_udp() && Self::check_server_udp_enabled(svr_cfg) {
                let checker = PingChecker {
                    server: server.clone(),
                    server_type: ServerType::Udp,
                    context: self.context.clone(),
                    max_server_rtt: self.max_server_rtt,
                };
                vfut_udp.push(checker.check_update_score());
            }
        }

        let check_tcp = vfut_tcp.len() > 1;
        let check_udp = vfut_udp.len() > 1;

        if !check_tcp && !check_udp {
            return;
        }

        let vfut = if !check_tcp {
            vfut_udp
        } else if !check_udp {
            vfut_tcp
        } else {
            vfut_tcp.append(&mut vfut_udp);
            vfut_tcp
        };

        future::join_all(vfut).await;

        if self.mode.enable_tcp() && check_tcp {
            let old_best_idx = self.best_tcp_idx.load(Ordering::Acquire);

            let mut best_idx = 0;
            let mut best_score = u32::MAX;
            for (idx, server) in servers.iter().enumerate() {
                let score = server.tcp_score().score();
                if score < best_score {
                    best_idx = idx;
                    best_score = score;
                }
            }
            self.best_tcp_idx.store(best_idx, Ordering::Release);

            if first_run {
                info!(
                    "chose best TCP server {}",
                    ServerConfigFormatter::new(servers[best_idx].server_config())
                );
            } else if best_idx != old_best_idx {
                info!(
                    "switched best TCP server from {} to {}",
                    ServerConfigFormatter::new(servers[old_best_idx].server_config()),
                    ServerConfigFormatter::new(servers[best_idx].server_config())
                );
            } else {
                debug!(
                    "kept best TCP server {}",
                    ServerConfigFormatter::new(servers[old_best_idx].server_config())
                );
            }
        }

        if self.mode.enable_udp() && check_udp {
            let old_best_idx = self.best_udp_idx.load(Ordering::Acquire);

            let mut best_idx = 0;
            let mut best_score = u32::MAX;
            for (idx, server) in servers.iter().enumerate() {
                let score = server.udp_score().score();
                if score < best_score {
                    best_idx = idx;
                    best_score = score;
                }
            }
            self.best_udp_idx.store(best_idx, Ordering::Release);

            if first_run {
                info!(
                    "chose best UDP server {}",
                    ServerConfigFormatter::new(servers[best_idx].server_config())
                );
            } else if best_idx != old_best_idx {
                info!(
                    "switched best UDP server from {} to {}",
                    ServerConfigFormatter::new(servers[old_best_idx].server_config()),
                    ServerConfigFormatter::new(servers[best_idx].server_config())
                );
            } else {
                debug!(
                    "kept best UDP server {}",
                    ServerConfigFormatter::new(servers[old_best_idx].server_config())
                );
            }
        }
    }
Check each servers' score and update the best server's index
crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs