Skip to content

Monitor how many UDP requests are aborted when the maximum number of concurrent requests is reached #830

@josecelano

Description

@josecelano

We handle a maximum of 50 UDP requests at the same time. When we have more than 50, we overwrite the latest one, and we give a second chance to the finish.

struct ActiveRequests {
    rb: StaticRb<AbortHandle, 50>, // the number of requests we handle at the same time.
}

// ...

async fn run_udp_server(tracker: Arc<Tracker>, socket: Arc<UdpSocket>) {
    let tracker = tracker.clone();
    let socket = socket.clone();

    let reqs = &mut ActiveRequests::default();

    // Main Waiting Loop, awaits on async [`receive_request`].
    loop {
        if let Some(h) = reqs.rb.push_overwrite(
            Self::spawn_request_processor(Self::receive_request(socket.clone()).await, tracker.clone(), socket.clone())
                .abort_handle(),
        ) {
            if !h.is_finished() {
                // the task is still running, lets yield and give it a chance to flush.
                tokio::task::yield_now().await;
                h.abort();
            }
        }
    }
}

The demo server has been busy recently and I'm curious how many UDP requests we are discarding (not even replying).

By the way @da2ce7 we are using the push_overwrite method.

image

That method overwrites the latest item, not the oldest. Does that make sense in our case? Would not be better if we overwrite the oldest request? That's the one that has had a longer time to be processed.

I'm planning to add a log (warning) before the h.abort() just to track the number of requests that are not processed. Then I can parse the logs to get the data like this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions