Slide 1

Slide 1 text

How GitLab scaled Git access with a Go service Oswaldo Ferreira (@olsfer) Backend Engineer at GitLab

Slide 2

Slide 2 text

Hi • Backend Engineer at GitLab Source Code Team • Merge Requests • Code Review • Web IDE • Enjoy hunting performance issues at GitLab.com • Moved to São Paulo about a year ago ✈

Slide 3

Slide 3 text

Today we'll cover • Introduction: What GitLab is • How GitLab use Git • How GitLab scaled Git storage and access • Limitations • Gitaly • gRPC, Protocol Buffers and Prometheus monitoring • How Gitaly fits into GitLab

Slide 4

Slide 4 text

Introduction (GitLab) • Single application for the whole DevOps lifecycle • Git repository hosting • Code reviewing • CI/CD • Monitoring • Security Testing • Etc • Open source projects written in Ruby, Javascript and Go

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Introduction (GitLab) • Started as a self-hosted application: You host your own GitLab instance • GitLab.com (SaaS) now handles about 3k Git operations per second (with around 9 million projects) • GitLab.com runs at GitLab Enterprise Edition, which has its stable packages released (for self-hosted clients) every 22nd

Slide 7

Slide 7 text

A bit of history • Early days of GitLab.com • Most of the application in a single server (Unicorn, Sidekiq, Git storage) • Easy to deploy and maintain • Only vertical scaling • Out of options for continuing scaling GitLab.com vertically • Horizontal scaling had to be made possible

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

How applications access Git • Libgit2 through Rugged • Libgit2 is a C implementation of Git core methods • Rugged is Ruby binding for libgit2 (so everyone could contribute) • Directly through Git command-line • A consolidated internal interface (Ruby) to interact with Git was built through time (reading and writing)

Slide 11

Slide 11 text

Horizontal scaling NFS (Network File System)

Slide 12

Slide 12 text

unicorn-1.server unicorn-2.server unicorn-3.server

Slide 13

Slide 13 text

git-1.server git-2.server git-3.server unicorn-1.server unicorn-2.server unicorn-3.server

Slide 14

Slide 14 text

git-1.server git-2.server git-3.server unicorn-1.server unicorn-2.server unicorn-3.server NFS mounting

Slide 15

Slide 15 text

Limitations

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

strace output Read .git/packed-refs Each line contains a SHA (ref name) Verify each ref exists (N times)

Slide 19

Slide 19 text

2k refs * 1ms = 2s

Slide 20

Slide 20 text

Low Fault Tolerance ❌ 
 Low visibility

Slide 21

Slide 21 text

git-1.server git-2.server git-3.server unicorn-1.server unicorn-2.server unicorn-3.server NFS mounting

Slide 22

Slide 22 text

git-1.server git-2.server git-3.server unicorn-1.server unicorn-2.server unicorn-3.server

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Gitaly

Slide 26

Slide 26 text

Ideas & Decisions • Concentrate all Git access logic within a single codebase (acting as a "git database") • gRPC and Protocol Buffers (cross-platform RPC and well defined API) • Written in Go • Prometheus for monitoring

Slide 27

Slide 27 text

git-1.server unicorn-1.server gRPC Make git work "locally" return the results over the network • NFS servers become Gitaly servers • Gitaly has direct disk access (no more NFS latency)

Slide 28

Slide 28 text

Development • New team to develop Gitaly • Slowly rollout and use it both on staging and production before Gitaly 1.0 (using feature flags)

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

• Open source message exchanging framework • Used by Slack and other beauties • Low latency, highly scalable • HTTP/2 • Protocol buffers as a descriptive language for interfaces

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

HTTP/2.0 streaming

Slide 35

Slide 35 text

pBuffers ✨ gRPC code .proto Ruby (Gitaly gem) ref_pb.rb Go bindings ref.pb.go Ruby Go protobuf tool C++, Java, Python, Go, Ruby, C#, Node.js, Objective-C, etc

Slide 36

Slide 36 text

pBuffers usage If the feature flag in ON:

Slide 37

Slide 37 text

pBuffers definition

Slide 38

Slide 38 text

But why not a JSON API? Or SOAP :troll:

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Advantages for our scenario • Mature interface for interacting with Git • Server to server binary message streaming • Numbered fields are powerful for versioning (backward compatible by default) • Language interoperability: Ruby client, Go server

Slide 42

Slide 42 text

Right, but can it ?

Slide 43

Slide 43 text

Collecting data

Slide 44

Slide 44 text

• Open source written in • Time series based monitoring • Own query language (PromQL) • Handles alerting • Great for monitoring (not great for general logging) • Error ratio, Request ratio, cache hit/miss

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

sum() • Faster message exchanging • Reliable typed interfaces between client/server • More visibility • Self-contained logic • Higher entry barrier for contributions • Additional complexity for maintaining • Funny enough: Higher visibility made us slower at first

Slide 50

Slide 50 text

Thanks!