# How Clash Nyanpasu Implements Latency Testing and Proxy Delay Measurement

> Clash Nyanpasu uses a dual-layer architecture for latency testing and proxy delay. Learn how Tauri backend and Clash core work together for accurate network measurements.

- Repository: [Nyanpasu/clash-nyanpasu](https://github.com/libnyanpasu/clash-nyanpasu)
- Tags: how-to-guide
- Published: 2026-03-06

---

**Clash Nyanpasu uses a dual-layer architecture where the Tauri backend performs direct HTTP latency tests via the `url_delay_test` command while the Clash core handles proxy-specific delay measurements through its REST API endpoint `/proxies/{name}/delay`.**

Latency testing and measuring proxy delay in Clash Nyanpasu relies on a sophisticated mechanism that bridges the frontend UI with both the Tauri runtime and the underlying Clash core. The application, hosted at `libnyanpasu/clash-nyanpasu`, implements complementary approaches to provide accurate network performance metrics for both direct URL tests and individual proxy connections.

## URL Latency Testing via Tauri Bridge

The first mechanism lives in [`frontend/interface/src/service/tauri.ts`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/frontend/interface/src/service/tauri.ts) and provides a lightweight method for testing the latency of any arbitrary URL. This approach bypasses the Clash core entirely and uses the Tauri runtime's HTTP capabilities.

The UI invokes the Tauri command **`url_delay_test`** using the Tauri bridge:

```typescript
import { invoke } from '@tauri-apps/api/tauri'

export async function testLatency(url: string): Promise<number | null> {
  // Calls the Rust command `url_delay_test`
  return await invoke<number | null>('url_delay_test', { 
    url, 
    expectedStatus: 204 
  })
}

```

On the Rust side, the command performs a simple HTTP `GET` request to the supplied URL using `reqwest` and returns the round-trip time in milliseconds. If the request fails or times out, it returns `null`. By default, this test uses the **default latency test URL** defined in the application configuration.

## Proxy-Specific Delay Measurement via Clash Core API

The second mechanism, located in [`frontend/interface/src/service/clash-api.ts`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/frontend/interface/src/service/clash-api.ts), measures the actual delay through a specific proxy by leveraging the Clash core's built-in testing capabilities. This provides a more accurate representation of the connection quality when traffic is routed through the proxy.

The UI sends requests to the Clash core endpoint:

```typescript
import request from '@/service/request'

export async function getProxyDelay(name: string): Promise<number> {
  const { delay } = await request<{ delay: number }>(
    `/proxies/${encodeURIComponent(name)}/delay`,
    { method: 'GET' }
  )
  return delay
}

```

The Clash core opens a TCP connection (or sends an HTTP request) through the selected proxy to the default latency test URL and measures the time taken for the response. The API returns a JSON object containing `{ delay: number }`, which the UI consumes and displays in the proxy list. For proxy groups, the endpoint `/group/{group}/delay` can be used to test all members simultaneously.

## Configuration and Default Test URLs

Both mechanisms rely on a configurable default latency test URL defined in [`backend/tauri/src/config/nyanpasu/mod.rs`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/backend/tauri/src/config/nyanpasu/mod.rs). The configuration struct contains:

```rust
pub default_latency_test: Option<String>

```

If the user does not set a custom URL, Clash Nyanpasu falls back to a built-in test address (typically `https://www.google.com/generate_204`). This value is passed to both the Tauri URL test and the Clash delay API, ensuring consistent measurement targets across both testing mechanisms.

## Visualizing Latency in the UI

Once latency data is collected, Clash Nyanpasu visualizes the results using color-coded thresholds defined in [`frontend/nyanpasu/src/hooks/theme.ts`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/frontend/nyanpasu/src/hooks/theme.ts). The **`useColorSxForDelay`** hook maps delay values to color schemes:

```typescript
import { useColorSxForDelay } from '@/hooks/theme'

function ProxyDelayChip({ delay }: { delay: number }) {
  const sx = useColorSxForDelay(delay)
  return <Chip label={`${delay} ms`} sx={sx} />
}

```

The UI typically applies a traffic-light system where green indicates low latency, orange represents medium delay, and red signals high latency or timeout conditions. This visual feedback allows users to quickly identify the fastest proxies in their configuration.

## Summary

- **Dual-measurement architecture**: Clash Nyanpasu combines direct HTTP tests via Tauri's `url_delay_test` command with proxy-tunneled measurements through the Clash core's `/proxies/{name}/delay` endpoint.
- **Configurable targets**: Both mechanisms use the `default_latency_test` configuration value from [`backend/tauri/src/config/nyanpasu/mod.rs`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/backend/tauri/src/config/nyanpasu/mod.rs), falling back to standard test URLs when not specified.
- **Frontend integration**: The UI bridges these mechanisms through [`frontend/interface/src/service/tauri.ts`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/frontend/interface/src/service/tauri.ts) and [`frontend/interface/src/service/clash-api.ts`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/frontend/interface/src/service/clash-api.ts), visualizing results using color thresholds defined in [`frontend/nyanpasu/src/hooks/theme.ts`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/frontend/nyanpasu/src/hooks/theme.ts).

## Frequently Asked Questions

### How does Clash Nyanpasu measure proxy delay differently from URL latency?

Clash Nyanpasu distinguishes between **URL latency testing** and **proxy delay measurement** by using different underlying mechanisms. URL latency tests execute direct HTTP `GET` requests from the Tauri backend to a target URL using `reqwest`, measuring raw network round-trip time without proxy interference. In contrast, proxy delay measurement routes the test traffic through the specific proxy node using the Clash core's `/proxies/{name}/delay` endpoint, providing the actual latency experienced when traffic flows through that proxy configuration.

### What is the default latency test URL used by Clash Nyanpasu?

When users do not specify a custom test target, Clash Nyanpasu falls back to a built-in default latency test URL, typically `https://www.google.com/generate_204`. This endpoint returns an HTTP 204 No Content response, making it ideal for lightweight latency measurement. The default value is managed through the `default_latency_test` configuration field in [`backend/tauri/src/config/nyanpasu/mod.rs`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/backend/tauri/src/config/nyanpasu/mod.rs) and is consumed by both the Tauri URL test command and the Clash core delay API.

### Where is the latency test configuration stored in Clash Nyanpasu?

The latency test configuration resides in the Rust backend at [`backend/tauri/src/config/nyanpasu/mod.rs`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/backend/tauri/src/config/nyanpasu/mod.rs). This module defines the configuration struct containing `pub default_latency_test: Option<String>`, which stores the user's preferred test URL. The configuration persists across application sessions and is accessible to both the frontend Tauri commands and the Clash core integration, ensuring consistent latency measurement targets throughout the application.

### How does the UI visualize different latency ranges?

The Clash Nyanpasu frontend visualizes latency using a color-coded system defined in [`frontend/nyanpasu/src/hooks/theme.ts`](https://github.com/libnyanpasu/clash-nyanpasu/blob/main/frontend/nyanpasu/src/hooks/theme.ts). The `useColorSxForDelay` hook maps numerical delay values to Material-UI `sx` style objects, applying a traffic-light color scheme where green indicates low latency (fast connection), orange represents medium delay, and red signals high latency or timeout conditions. This visualization appears in proxy list items and group selectors, allowing users to instantly identify the fastest available proxy nodes.