Σημείωμα
Η πρόσβαση σε αυτήν τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να εισέλθετε ή να αλλάξετε καταλόγους.
Η πρόσβαση σε αυτήν τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να αλλάξετε καταλόγους.
Optimize Model Serving endpoints for production workloads that need high throughput and low latency.
Optimization strategies fall into three categories:
- Infrastructure optimizations: Configure endpoint infrastructure, such as routing and concurrency.
- Model optimizations: Improve model efficiency and throughput
- Client-side optimizations: Optimize how clients interact with serving endpoints.
When to optimize your endpoint
Consider optimizing your Model Serving endpoint when you encounter any of the following scenarios:
- High query volume: Your application sends more than 50k queries per second (QPS) to a single endpoint
- Latency requirements: Your application requires sub-100ms response times
- Scaling bottlenecks: Endpoints experience queuing or return HTTP 429 errors during traffic spikes
- Cost optimization: You want to reduce serving costs while maintaining performance targets
- Production preparation: You're preparing to move from development to production workloads
Infrastructure optimizations
Infrastructure optimizations improve network routing, scaling behavior, and compute capacity.
Route optimization
Route optimization is an infrastructure setting for high-throughput workloads. When you enable it on an endpoint, Model Serving uses a more direct network path for inference requests between your client and the model. Route-optimized endpoints use their own URL and an OAuth token that carries authorization_details for the endpoint.
Limits with and without route optimization:
| Feature | Standard endpoint limit | Route optimized endpoint limit |
|---|---|---|
| Queries per second (QPS) per workspace | 200 | 50,000+ (contact Databricks for higher limits) |
| Client concurrency per workspace | 192-1024 (varies by region) | No explicit limit (limited by provisioned concurrency) |
| Endpoint provisioned concurrency per served entity | 2,048 | 2,048 (contact Databricks for higher limits) |
For the current limits, see Model Serving limits and regions.
When to use route optimization:
- Workloads requiring more than 200 QPS
- Applications with strict latency requirements (sub-50ms overhead)
- Production deployments serving multiple concurrent users
Important
Route optimization is only available for custom model serving endpoints. Foundation Model APIs and external models do not support route optimization. OAuth tokens are required for authentication. Personal access tokens are not supported.
See Route optimization for Model Serving endpoints for setup instructions and Query route-optimized serving endpoints for querying details.
Provisioned concurrency
Provisioned concurrency controls how many simultaneous requests your endpoint can process. Configure provisioned concurrency based on your expected QPS and latency requirements. Set the minimum and maximum with min_provisioned_concurrency and max_provisioned_concurrency, as shown in Create an endpoint.
Configuration guidelines:
- Minimum concurrency: Set high enough to handle baseline traffic without queuing.
- Maximum concurrency: Set high enough to accommodate traffic spikes while controlling costs.
- Autoscaling: Capacity scales between minimum and maximum. Set them equal for fixed capacity.
- Scale to zero: Scale to zero isn't recommended for production workloads, especially latency-sensitive workloads and GPU workloads.
Calculate required concurrency:
Required Concurrency = Target QPS × Average Latency (seconds)
For example, if your target is 100 QPS with 200ms average latency:
Required Concurrency = 100 × 0.2 = 20
Use load testing to measure actual latency and determine optimal concurrency settings.
Custom LLM endpoints don't scale between a minimum and a maximum. They run at a fixed provisioned concurrency.
To change the minimum or maximum on a running endpoint, update its configuration. The endpoint keeps serving its current configuration until the update finishes. To add capacity before a known burst, update the endpoint ahead of time, for example from a scheduled job. See Update an endpoint's configuration.
Workload types
Choose a workload type based on your model's compute requirements. Small, Medium, and Large are workload sizes, which you set separately.
| Workload type | Best for | Trade-offs |
|---|---|---|
| CPU workload type | Lightweight models, simple inference logic | Lower cost. Less suited to compute-intensive models |
GPU workload types, such as GPU_SMALL and GPU_MEDIUM |
Large models, complex computations, image/video processing | Higher cost. Used for deep learning workloads |
Tip
Start with CPU workloads for development and testing. Switch to GPU workloads only if you observe high inference latency or your model requires specialized compute (such as deep learning operations).
Model optimizations
Model optimizations reduce the compute that each request needs.
Model size and complexity
A smaller or less complex model needs less compute for each request. Consider techniques like model quantization or pruning if your model is large.
Batching
If your application can send multiple requests in a single call, enable batching at the client side. Each request carries overhead, so batching spreads that overhead across more predictions.
Pre-processing and post-processing optimization
Offload complex pre-processing and post-processing from serving endpoints to reduce load on inference infrastructure.
Client-side optimizations
Client-side optimizations improve how applications interact with serving endpoints.
Connection pooling
Connection pooling reuses existing connections instead of creating new connections for each request, which cuts connection setup work.
- Use the Databricks SDK, which automatically implements connection pooling best practices
- Reuse one
WorkspaceClientfor your calls, because each client has its own connection pool. - If using custom clients, implement connection pooling yourself.
Error handling and retry strategies
Handle temporary failures in your client code, especially during autoscaling events or network disruptions.
Payload size optimization
Minimize request and response payload sizes to reduce network transfer time and improve throughput. Each request is limited to 16 MiB for custom model and agent endpoints. For all limits, see Model Serving limits and regions.
Measure and improve performance
Performance monitoring
Monitor endpoint performance using the tools provided by Model Serving:
| Metric | What it measures | Target | Action if exceeded |
|---|---|---|---|
| Latency (P50, P90, P99, meaning the median, 90th, and 99th percentiles) | Response time for requests | Application-dependent (typically <100-500ms) | Check for queuing, optimize model or client |
| Throughput (QPS) | Requests completed per second | Workload-dependent | Enable route optimization, increase provisioned concurrency |
| Error rate | Percentage of failed requests | <1% | Review service logs, check for capacity issues |
| Queue depth | Requests waiting for processing | 0 (no queuing) | Increase the minimum or maximum provisioned concurrency |
| CPU/Memory usage | Resource utilization | <80% | Scale up instance type or increase concurrency |
See Monitor Model Serving endpoints for detailed monitoring guidance and Metrics for Model Serving endpoints for exporting metrics to observability tools.
Load testing
Load testing measures endpoint performance under realistic traffic conditions and helps you:
- Determine optimal provisioned concurrency settings
- Identify performance bottlenecks
- Validate latency and throughput requirements
- Understand the relationship between client concurrency and server concurrency
See Size and load test custom model serving endpoints.
Troubleshoot common performance issues
Queuing
Model Serving supports autoscaling to adjust capacity based on traffic patterns. However, sudden traffic surges can cause queuing because autoscaling requires time to detect increased load and provision additional capacity. During this period, incoming requests may temporarily exceed available capacity, and the excess requests queue.
Queuing occurs when the request rate or concurrency surpasses the endpoint's current processing capacity. This typically happens during sharp traffic spikes, workload bursts, or when the endpoint has insufficient provisioned concurrency. Model Serving endpoints allow temporary queuing to handle bursts, but beyond a defined threshold, the endpoint returns HTTP 429 (Too Many Requests) errors to protect system stability.
Queuing increases latency because queued requests wait before being processed. To minimize queuing:
- Set minimum provisioned concurrency high enough to handle baseline traffic plus typical bursts
- Enable route optimization for higher capacity limits
- Implement retry logic with exponential backoff in your client applications
External API bottlenecks
Models often call external APIs for data enrichment, feature retrieval, or other tasks during inference. These external dependencies can become performance bottlenecks:
- Latency: Measure the response time of each external API call. High latency in these calls directly increases overall serving latency and reduces throughput.
- Throughput limits: External APIs may impose rate limits or capacity constraints. Exceeding these limits can cause throttling, errors, and performance degradation.
- Error rates: Frequent errors from external APIs can trigger retries and increase load on your serving endpoint.
- Caching: Implement caching for frequently accessed data from external APIs to reduce the number of calls and improve response times.
Monitor these factors to find the external calls that slow your endpoint, and optimize those calls.
Blocking calls in model code on CPU endpoints
On CPU custom model serving endpoints that use gevent workers, a call that blocks in compiled code can stall every request on that worker, even when the call runs in a background thread. To avoid this, run such calls on a separate pool of operating system (OS) threads.
A gevent worker can serve several requests at the same time. Python threads that your model code starts, including threading.Thread and concurrent.futures.ThreadPoolExecutor, run as cooperative gevent tasks on the worker's thread. They switch only at calls that gevent makes cooperative, such as socket I/O, time.sleep, and locks, so pure-Python network I/O, for example with requests, works as expected. A call that waits inside compiled code, such as a C, C++, or Rust extension, some database drivers, or some SDKs, doesn't switch, so it holds the whole worker until it returns. A common symptom is latency spikes or timeouts on many requests at the same time that line up with a slow downstream service.
To check whether your endpoint uses gevent workers, log gevent.monkey.is_module_patched("threading") when your model loads. On endpoints that don't use gevent, a blocking call delays only the request that made it.
The following helper runs a call on a dedicated pool of OS threads when gevent is active, and calls it directly otherwise:
_pool = None
def run_blocking(fn, *args, **kwargs):
"""Run fn on an OS thread when gevent is active. Otherwise, call fn directly."""
try:
from gevent import monkey
from gevent.threadpool import ThreadPool
except ImportError:
return fn(*args, **kwargs)
if not monkey.is_module_patched("threading"):
return fn(*args, **kwargs)
global _pool
if _pool is None:
_pool = ThreadPool(8)
return _pool.apply(fn, args, kwargs)
For example, in a background thread that writes records with an SDK client that waits in compiled code, call run_blocking(client.write, record) instead of client.write(record). Keep the following in mind:
fnruns on a different thread than the caller, and several calls can run at the same time. Use it only with thread-safe objects, create thread-bound objects such as database connections insidefn, and pass request-specific values as arguments.contextvarsand thread-local values that the caller sets aren't visible insidefn. Callrun_blockingfrom Python code that your model runs, not from a callback that a compiled library runs on its own thread.- Set a timeout on the blocking call itself. A pool thread can't be canceled, so a call that never returns keeps its thread. When all pool threads are busy, new calls wait for a free thread.
- Offloading helps only if the compiled call releases the Python global interpreter lock (GIL) while it waits.
- If
fnraises an exception,run_blockingraises it in the caller.
To write logs or per-request records to a table, use endpoint telemetry instead of a blocking call. See Persist custom model serving data to Unity Catalog.
Additional resources
| Resource | Description |
|---|---|
| Route optimization for Model Serving endpoints | Lower overhead latency and raise throughput with route optimization. |
| Size and load test custom model serving endpoints | Size an endpoint with a load test. |