This page provides a comprehensive overview of how each Sourcegraph service scales.
In order to support the growth of your instance usage, it is recommended to scale Sourcegraph based on the scaling factors suggested below.
Grafana should be the first stop you make if you plan to expand on one of the scaling factors or when you are experiencing a system performance issue.
Please use the following scaling guideline for services that are using more than 80% of their assigned resources.
Scaling is unnecessary if your resource usage is kept below 80%.
For example, if you plan to add 100% more engaged users, and the resource usage for all services is currently at around 70%, we’d recommend using this documentation as a reference to adjust the resources that list “Number of active users” as one of their scaling factors. You can also use the output from the Resource Estimator as references alternatively.
For assistance when scaling and tuning Sourcegraph, contact us. We're happy to help!
Serves the web application, extensions, and graphQL services. Almost every service has a link back to the frontend, from which it gathers configuration updates.
Tracks the state of repositories. It is responsible for automatically scheduling updates using gitserver and for synchronizing metadata between code hosts and external services.
Runs searches from indexes stored in memory and disk. The indexes are persisted to disk to avoid re-indexing on startup. Lives inside the indexed-search pod in a Kubernetes deployment.
A PostgreSQL instance for storing long-term information, such as user information when using Sourcegraph’s built-in authentication provider instead of an external one.
Sourcegraph provides a number of tools to monitor the health and usage of your deployment. See our Observability docs for more information.
You can also learn more about the architecture of Sourcegraph’s monitoring stack in Sourcegraph monitoring architecture
This section provides you with a high-level overview of how each Sourcegraph service works with resources, with a list of scaling factors and basic guideline.
A PostgreSQL instance for storing code insights data.
Replica
Overview
Singleton
Factors
-
Guideline
A Singleton service should not have more than 1 replica
CPU
Overview
Executes queries
Factors
Number of active users
Number of repositories
Number of insight series defined
Number of matches per insight series
Compression ratio of insight data
Guideline
Keep the total memory larger than the largest index
Memory
Overview
Process Indexes
Factors
Number of active users
Size of all repositories
Number of repositories
Number of insight series defined
Number of matches per insight series
Compression ratio of insight data
Guideline
Keep the total memory larger than the largest index
Storage
Overview
Stores code insights data
Factors
Number of insight series defined
Number of matches per insight series
Compression ratio of insight data
Guideline
Depends entirely on usage and the specific Insights that are being created
Type
Persistent Volumes for Kubernetes
Persistent SSD for Docker Compose
The database must be configured properly to consume resources effectively and efficiently for better performance and to avoid regular usage from overwhelming built-in utilities (like autovacuum for example). For example, a Postgres database running out of memory indicates that it is currently misconfigured, and the amount of memory each worker can utilize should be reduced. See our Postgres database configuration guide for more information.
A PostgreSQL instance for storing large-volume code graph data.
Replica
Overview
Singleton
Factors
-
Guideline
A Singleton service should not have more than 1 replica
CPU
Overview
Executes queries
Factors
Number of active users
Frequency with which the instance runs precise code navigation queries
Guideline
The default value should work for all deployments. Please refer to the note below for more detail
Memory
Overview
Process LSIF indexes
Factors
Number of active users
Frequency with which the instance runs precise code navigation queries
Total size of repositories indexed by Rockskip
Guideline
The database must be configured properly to consume resources effectively and efficiently. See note below for more detail
The amount of memory each Postgres worker can utilize must be adjusted according to the memory assigned to the database
Increase the memory assigned to each worker proportionally when database queries are slow
Storage
Overview
Stores processed upload data
Factors
Number and size of precise code graph data uploads
Indexer used
Guideline
The index size and processed size are currently based on indexer used
Requires about 4 times of the total size of repositories indexed by Rockskip
SCIP provides a more stable approximation of index size -> processed
Type
Persistent Volumes for Kubernetes
Persistent SSD for Docker Compose
The database must be configured properly to consume resources effectively and efficiently for better performance and to avoid regular usage from overwhelming built-in utilities (like autovacuum for example). For example, a Postgres database running out of memory indicates that it is currently misconfigured, and the amount of memory each worker can utilize should be reduced. See our Postgres database configuration guide for more information.
A blobstore instance that serves as local S3-compatible object storage. Itholds files such as search jobs results and index uploads for precise codenavigation.
Replica
Overview
Singleton
Factors
-
Guideline
A Singleton service should not have more than 1 replica
CPU
Overview
The default setup should be sufficient for most deployments
Factors
-
Guideline
-
Memory
Overview
The default setup should be sufficient for most deployments
The main database. A PostgreSQL instance.Data stored include repo lists, user data, worker queue , and site-config files etc.Data for code-insights related to running queries are also stored here.Basically anything not related to code-intel.
Replica
Overview
Singleton
Factors
-
Guideline
A Singleton service should not have more than 1 replica
CPU
Overview
Executes queries
Factors
The default setup should be sufficient for most deployments
Guideline
The database must be configured properly following our Postgres configuration guide to use the assigned resources efficiently
Memory
Overview
Linear to the concurrent number of API requests proxies
Factors
The default setup should be sufficient for most deployments
Guideline
The database must be configured properly following our Postgres configuration guide to use the assigned resources efficiently
Storage
Overview
The Postgres instance will use memory by bringing OS pages into resident memory where it will control its own allocations
Factors
Size of all repositories
Number of insight queries
Guideline
Starts at default as the value grows depending on the number of active users and activity
The database must be configured properly following our Postgres configuration guide to use the assigned resources efficiently
Type
Persistent Volumes for Kubernetes
Persistent SSD for Docker Compose
The database must be configured properly to consume resources effectively and efficiently for better performance and to avoid regular usage from overwhelming built-in utilities (like autovacuum for example). For example, a Postgres database running out of memory indicates that it is currently misconfigured and the amount of memory each worker can utilize should be reduced. See our Postgres database configuration guide for more information.
A customized Prometheus instance for collecting high-level and low-cardinality, metrics across services.It currently bundles Alertmanager as well as integrations to the Sourcegraph web application.
Resources
Overview
The default setup should be sufficient for most deployments
Factors
Number of active users
Guideline
For Kubernetes deployments, please follow the instruction here to prevent Prometheus from scraping metrics outside of your Sourcegraph namespace
Repo-updater tracks the state of repositories.It is responsible for automatically scheduling updates using gitserver.It is also responsible for synchronizing metadata between code hosts and external services.Services that desire updates or fetch must communicate with repo-updater instead of gitserver.
Replica
Overview
Singleton
Factors
-
Guideline
A Singleton service should not have more than 1 replica
CPU
Overview
Most operations are not CPU bound
Factors
Most of the syncing jobs are related more to internal and code host-specific rate limits
Guideline
-
Memory
Overview
The queue of repositories that need to be updated is stored in memory. It uses an in-memory queue and is mostly network intensive as it makes API calls and processes and writes those newly available data to the pgsql database
Factors
Number of repositories
Guideline
This service is safe to restart at any time. The existing in-memory update queue is reset upon restart
Not memory intensive
Storage
Overview
A stateless service that directly writes to the pgsql database
An HTTP server that exposes the Rust Syntect syntax highlighting library to other services.
Replica
Overview
The constant overhead applies per worker process. Having a large number of processes is not necessarily useful (consumes more memory while idling) if there aren't many active users
Factors
Number of active users
Guideline
More users = more CPU and replicas
Add replica when syntax highlighting queries take a long duration because of existing traffic
CPU
Overview
There are a number of worker processes, each with some number of threads. When a syntax highlighting request comes in, it is dispatched to a process, which further sends it to the worker thread. When there are no requests, CPU consumption should be minimal
Factors
Number of active users
Guideline
More users = more CPU and replicas
Memory
Overview
A lot of the highlighting themes and compiled grammars are loaded into memory at start up
Factors
Number of active users
Guideline
There is additional memory consumption on receiving requests (< 25 MB), although, that's generally much smaller than the constant overhead (1-2 GB)
Indexes all enabled repositories on Sourcegraph.It also keeps the indexes up to date.Lives inside the indexed-search pod in a Kubernetes deployment.The main guideline for scaling a zoekt-indexserver is the size of your largest repository.
As indexserver currently only indexes one repository at a time, having more CPU and memory are not as important here than in webserver.
Replica
Overview
Parallel with zoekt-webserver
Factors
Size of the largest repository
Guideline
Scales with zoekt-webserver
Replicas number must be parallel with zoekt-webserver
CPU
Overview
Indexes one repository at a time
Factors
Size of the largest repository
Guideline
More CPU results in lower lag between a new commit and the time it takes to index for search
Memory
Overview
Scans for symbols
Factors
Size of the largest repository
Guideline
In general the amount of RAM used will max out at 100MB * number of CPUS * constant factor (around 5 in practice)
Storage
Overview
Stores index. Storage is shared with zoekt-webserver
Factors
Size of all repositories
Guideline
50% of the gitserver disk size
Disk IO is important as it constantly reads from disk during searches
Scale with zoekt-webserver
Type
Persistent Volumes for Kubernetes
Persistent SSD for Docker Compose
We recommend providing zoekt-indexserver with more resources when trying to add a lot of new repositories that requires indexing from a new external service, and then scale down once indexing is completed.
Runs searches from indexes stored in memory and disk.It serves and processes data from zoekt-indexserver.The indexes are persisted to disk to avoid re-indexing on startup.Lives inside the indexed-search pod in a Kubernetes deployment.
Adding more CPU and memory helps speed up searches.
Replica
Overview
Parallel with zoekt-indexserver
Factors
Number of repositories
Size of all repositories
Guideline
More repositories = more CPU and replicas
Replicas number must be parallel with zoekt-indexserver
CPU
Overview
Goroutines are dispatched per search query
Factors
Number of repositories
Number of active users
Guideline
Scales with the number of search requests
More search requests = more CPU and replicas
Memory
Overview
Parts of the index are stored in memory
Factors
Number of repositories
Size of all repositories
Guideline
Scales with the number of repositories
More repositories = more memory
Storage
Overview
Stores index. Storage is shared with zoekt-indexserver.
Factors
Size of all repositories
Guideline
50% of the gitserver disk size
Disk IO is important as it constantly reads from disk during searches
Scale with zoekt-indexserver
Type
Persistent Volumes for Kubernetes
Persistent SSD for Docker Compose
Check the peak bursts rather than the average over time when monitoring CPU usage for zoekt as it depends on when the searches happen.