gitaly

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2017 License: MIT

README

Gitaly

What

Gitaly is a Git RPC service for handling all the git calls made by GitLab.

To see where it fits in please look at GitLab's architecture

Gitaly is still under development. We expect it to become a standard component of GitLab in Q1 2017 and to reach full scope in Q3 2017.

Project Goals

Make the git data storage tier of large GitLab instances, and GitLab.com in particular, fast.

This will be achieved by focusing on two areas (in this order):

  1. Allow efficient caching
  2. Resilient horizontal scaling of GitLab's Git data tier
Scope

To maintain the focus of the project, the following subjects are out-of-scope for the moment:

  1. Replication and high availability (including multi-master and active-active).

References

Name

Gitaly is a tribute to git and the town of Aly. Where the town of Aly has zero inhabitants most of the year we would like to reduce the number of disk operations to zero for most actions. It doesn't hurt that it sounds like Italy, the capital of which is the destination of all roads. All git actions in GitLab end up in Gitaly.

Reason

For GitLab.com the git access is slow.

When looking at Rugged::Repository.new performance data we can see that our P99 spikes up to 30 wall seconds, while the CPU time keeps in the realm of the 15 milliseconds. Pointing at filesystem access as the culprit.

rugged.new timings

Our P99 access time to just create a Rugged::Repository object, which is loading and processing the git objects from disk, spikes over 30 seconds, making it basically unusable. We also saw that just walking through the branches of gitlab-ce requires 2.4 wall seconds.

We considered to move to metal to fix our problems with higher performaning hardware. But our users are using GitLab in the cloud so it should work great there. And this way the increased performance will benefit every GitLab user.

Gitaly will make our situation better in a few steps:

  1. One central place to monitor operations
  2. Performance improvements doing less and caching more
  3. Move the git operations from the app to the file/git server with git rpc (routing git access over JSON HTTP calls)
  4. Use Git ketch to allow active-active (push to a local server), and distributed read operations (read from a secondary). This is far in the future, we might also use a distributed key value store instead. See the active-active issue. Until we are active active we can just use persistent storage on the cloud to shard, this eliminates the need for redundancy.

Decisions

All design decision should be added here.

  1. Why are we considering to use Git Ketch? It is open source, uses the git protocol itself, is made by experts in distributed systems (Google), and is as simple as we can think of. We have to accept that we'll have to run the JVM on the Git servers.
  2. We'll keep using the existing sharding functionality in GitLab to be able to add new servers. Currently we can use it to have multiple file/git servers. Later we will need multiple Git Ketch clusters.
  3. We need to get rid of NFS mounting at some point because one broken NFS server causes all the application servers to fail to the point where you can't even ssh in.
  4. We want to move the git executable as close to the disk as possible to reduce latency, hence the need for git rpc to talk between the app server and git.
  5. Cached metadata is stored in Redis LRU
  6. Cached payloads are stored in files since Redis can't store large objects
  7. Why not use GitLab Git? So workhorse and ssh access can use the same system. We need this to manage cache invalidation.
  8. Why not make this a library for most users instead of a daemon/server?
    • Centralization: We need this new layer to be accessed and to share resources from multiple sources. A library is not fit for this end.
    • A library would have to be used in one of our current components, none of which seems ideal to take on this task:
      • gitlab-shell: return to the gitolite model? No.
      • Gitlab-workhorse: is now a proxy for Rails; would then become simultaneous proxy and backend service. Sounds confusing.
      • Unicorn: cannot handle slow requests
      • Sidekiq: can handle slow jobs but not requests
      • Combination workhorse+unicorn+sidekiq+gitlab-shell: this is hard to get right and slow to build even when you are an expert
    • With a library we will still need to keep the NFS shares mounted in the application hosts. That puts a hard stop to scale our storage because we need to keep multiplying the NFS mounts in all the workers.
  9. Can we focus on instrumenting first before building Gitaly? Prometheus doesn't work with Unicorn.
  10. How do we ship this quickly without affecting users? Behind a feature flag like we did with workhorse. We can update it independently in production.
  11. How much memory will this use? Guess 50MB, we will save memory in the rails app, guess more in sidekiq (GBs but not sure), but initially more because more libraries are still loaded everywhere.
  12. What packaging tool do we use? Govendor because we like it more
  13. How will the networking work? A unix socket for git operations and TCP for monitoring. This prevents having to build out authentication at this early stage. https://gitlab.com/gitlab-org/gitaly/issues/16
  14. We'll include the /vendor directory in source control https://gitlab.com/gitlab-org/gitaly/issues/18
  15. We will use E3 from BitBucket to measure performance closely in isolation.
  16. Use environment variables for setting configurations (see #20).
  17. GitLab already has logic so that the application servers know which file/git server contains what repository, this eliminates the need for a router.
  18. Use gRPC instead of HTTP+JSON. Not so much for performance reasons (Protobuf is faster than JSON) but because gRPC is an RPC framework. With HTTP+JSON we have to invent our own framework; with gRPC we get a set of conventions to work with. This will allow us to move faster once we have learned how to use gRPC.
  19. All protocol definitions and auto-generated gRPC client code will be in the gitaly repo. We can include the client code from the rest of the application as a Ruby gem / Go package / client executable as needed. This will make cross-repo versioning easier.
  20. Gitaly will expose high-level Git operations, not low-level Git object/ref storage lookups. Many interesting Git operations involve an unbounded number of Git object lookups. For example, the number of Git object lookups needed to generate a diff depends on the number of changed files and how deep those files are in the repository directory structure. It is not feasible to make each of those Git object lookups a remote procedure call.
  21. By default all Go packages in the Gitaly repository use the /internal directory, unless we explicitly want to export something. The only exception is the /cmd directory for executables.

Iterate

More on the Gitaly Process here

Instead of moving everything to Gitaly and only then optimize performance we'll iterate so we quickly have results

The iteration process is as follows:

  1. Move a specific set of functions from Rails to Gitaly without performance optimizations (needs to happen before release, there is a switch to use either Rails or Gitaly)
  2. Measure their original performance
  3. Try to improve the performance by reducing reads and/or caching
  4. Measure the effect and if warrented try again
  5. Remove the switch from Rails

Some examples of a specific set of functions:

Based on the daily overview dashboard, we should tackle the routes in gitlab-rails in the following order:

Order of Migration

Using data from the daily overview dashboard, we've prioritised the order in which we'll work through the gitlab-rails controllers in descending order of 95% Cumulative Time (that is (number of calls) * (95% call time)).

A Google Spreadsheet is available with these calculations.

Controller Analysis Migration Optim 1 Optim 2
SmartHTTP Workhorse Interceptors #36
Projects::CommitController#show #64
Projects::MergeRequestsController#ci_status.json #66
Projects::MergeRequestsController#ci_environments_status.json #66
Projects::TreeController#show #65
RootController#index
Projects::RawController#show
Projects::BlobController#show
ProjectsController#show
Projects::BranchesController#index
Projects::RefsController#logs_tree
GroupsController#show
Projects::MergeRequestsController#show
Dashboard::ProjectsController#index
Explore::ProjectsController#trending
Projects::MergeRequestsController#new
Projects::MergeRequestsController#create
Projects::BuildsController#show
Explore::ProjectsController#index
Projects::GitHttpController#git_upload_pack.json

(More to follow!)

Plan

We use our issues board for keeping our work in progress up to date in a single place. Please refer to it to see the current status of the project.

  1. Absorb gitlab_git
  2. Milestone 0.1
  3. Move more functions in accordance with the iterate process, starting with the ones with have the highest impact.
  4. Change the connection on the workers from a unix socket to an actual TCP socket to reach Gitaly
  5. Build Gitaly fleet that will have the NFS mount points and will run Gitaly
  6. Move to GitRPC model where GitLab is not accessing git directly but through Gitaly
  7. Remove the git NFS mount points from the worker fleet
  8. Remove gitlab git from Gitlab Rails
  9. Move to active-active with Git Ketch, with this we can read from any node, greatly reducing the number of IOPS on the leader.
  10. Move to the most performant and cost effective cloud

Design

High-level architecture overview:

Gitaly Architecture

Edit this diagram directly in Google Drawings

Directories

Path Synopsis
cmd
internal
protos
go
Package gitaly is a generated protocol buffer package.
Package gitaly is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL