The jDisc container is Vespa’s powerful runtime environment that hosts application components. It provides dependency injection, lifecycle management, and a flexible component model for building search and document processing applications.Documentation Index
Fetch the complete documentation index at: https://support.agentrank.io/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The jDisc container is the foundation of Vespa’s extensibility. It manages:- Component lifecycle - Creation, initialization, and destruction
- Dependency injection - Automatic wiring of component dependencies
- Request handling - Routing requests to appropriate handlers
- Resource management - Reference counting and cleanup
Container Architecture
The container is immutable once created. Each reconfiguration produces a new container instance:jdisc_core/src/main/java/com/yahoo/jdisc/Container.java:30
Component Lifecycle
Components in the jDisc container follow a well-defined lifecycle:Construction
The container creates component instances using constructor injection. Dependencies are automatically resolved and injected.
In Service
Components handle requests from multiple threads in parallel. This phase lasts until the container is replaced during reconfiguration.
Dependency Injection
The container uses constructor-based dependency injection:Constructor Selection
When multiple constructors exist, the container selects them in this priority order:- Constructor with
ComponentId+ highest number of config parameters - Constructor with
Stringid + highest number of config parameters - Constructor with only config parameters (highest number)
- Constructor with
ComponentIdonly - Constructor with
Stringid only - Default (no-argument) constructor
container-search/src/main/java/com/yahoo/search/Searcher.java:43
Provider Pattern
For advanced component creation, implement theProvider interface:
component/src/main/java/com/yahoo/container/di/componentgraph/Provider.java:6
Providers are useful when:
- Complex initialization logic is required
- Resources need explicit cleanup
- You want to provide a fallback component
Application Interface
Applications implement theApplication interface to control the container lifecycle:
jdisc_core/src/main/java/com/yahoo/jdisc/application/Application.java:16
Container Activation
To create and activate a new container:Request Lifecycle
Each request is attached to a container instance:- Request arrives - The container resolves the appropriate
RequestHandler - Processing - The handler processes the request (searcher chain, document processor chain, etc.)
- Release - When
request.release()is called, the container reference is released
Thread Safety
Components must be thread-safe:- Immutable state - Prefer immutable data structures created in the constructor
- Read-only access - Build data in constructor, access read-only afterwards
- Synchronization - Only when absolutely necessary (impacts performance)
container-search/src/main/java/com/yahoo/search/Searcher.java:37
Best Practices
Use Constructor Injection
Use Constructor Injection
Always use constructor injection rather than
getInstance(). This makes dependencies explicit and testable.Keep Constructors Fast
Keep Constructors Fast
Constructors block container reconfiguration. Avoid expensive operations like network calls or large file I/O.
Implement Proper Cleanup
Implement Proper Cleanup
Override
deconstruct() to clean up resources like thread pools, connections, or file handles.Make Components Thread-Safe
Make Components Thread-Safe
Components serve multiple requests concurrently. Use immutable data structures and avoid mutable shared state.
Related APIs
- Searcher API - Search chain components
- Document Processor API - Document processing components
- Component API - Base component interfaces