> ## Documentation Index
> Fetch the complete documentation index at: https://docs.verity.usher.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Thread Pool Management

> Verity's Prover includes a mechanism to optimise proving times.

The Verity Prover includes a mechanism to initialise warm MPC connection threads by server domain.

This feature significantly improves time to response (**TTR**) and time to proof (**TTP**).

**By default**, each request to the `/proxy` endpoint triggers the setup of a new MPC connection thread in a **cold start** manner. This process takes 2–3 seconds per request, depending on the geographic distance between the Prover and the source server.

With **thread management**, the Prover can pre-prepare these connections for expected requests to the source server domain. This enables a **warm start**, cutting the response time for verifiable requests by 2–3 seconds.

**Note:** TTR increases proportionally with the size of the request/response:

1. For data transfers \< 3 KB, TTR is 1–5 seconds.
2. For data transfers \~25 KB, TTR increases to around 20 seconds.

### Managing Thread Pools

```
GET http://localhost:8080/pools

###

GET http://localhost:8080/pools/example.com

###

POST http://localhost:8080/pools
Content-Type: application/json

{
  "domain": "example.com",
  "capacity": 2
}

###

DELETE http://localhost:8080/pools/example.com

###
```

### **Pool management via `/pools` API endpoint**

To get statistics of all the pools

```bash theme={null}
curl http://localhost:8080/pools
```

To get statistics of pool for a specific domain

```bash theme={null}
curl http://localhost:8080/pools/api.coingecko.com
```

To create a pool for a domain

```bash theme={null}
curl \
  -X POST http://localhost:8080/pools \
  -H 'content-type: application/json' \
  -d '{ "domain": "api.coingecko.com", "capacity": 2 }'
```

To drop an existing pool

```bash theme={null}
curl \
  -X DELETE http://localhost:8080/pools/api.coingecko.com
```

### Creating a pool via `/proxy` API endpoint and `T-PREPARE` header

<Note>
  This works only for the very first proxy request, when there is no pool for the domain. If the pool already exists, the `T-PREPARE` header is ignored.
</Note>

```bash theme={null}
curl http://localhost:8080/proxy \
  -H 'T-PROXY-URL: https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd' \
  -H 'T-PREPARE: 2'
```

### Creating a pool by defining it in the Prover configuration file

To create a pool at prover startup, define it in the Prover configuration file:

```yaml theme={null}
port: 8080
notary:
  host: prover.verity.usher.so
  port: 7047
  enable-tls: true
  max-sent-data: 512 # default value for a pool
  max-recv-data: 1024 # default value for a pool
  timeout: 30 # default value for a pool
num-threads: 4
domains: # defines a list of pools with parameter to override default values set above
  - domain: example.com
    capacity: 2 # optional, if not defined, the pool will spawn a connection on demand
    max-sent-data: 1024 # optional, overrides default value if set
    max-recv-data: 2048 # optional, overrides default value if set
    timeout: 60 # optional, overrides default value if set
```

### Proxying requests concurrently

```bash theme={null}
set +m
jobs=()
for currency in "bitcoin" "ethereum" "solana"
do
  {
    curl http://localhost:8080/proxy \
      -w "\ntime: %{time_total}\n" \
      -H "T-PROXY-URL: https://api.coingecko.com/api/v3/simple/price?ids=$currency&vs_currencies=usd"
  } &
  jobs+=($!)
done
wait "${jobs[@]}"
```
