Skip to content

Experimental support for P2P Volume Streaming - #6186

Merged
taylorsilva merged 4 commits into
concourse:masterfrom
evanchaoli:p2p-streaming
Nov 12, 2020
Merged

taylorsilva merged 4 commits into
concourse:masterfrom
evanchaoli:p2p-streaming

Conversation

@evanchaoli

@evanchaoli evanchaoli commented Oct 21, 2020 •

Copy link
Copy Markdown
Contributor

What does this PR accomplish?

This PR implements P2P Volume Streaming (concourse/rfcs#82). In deployments where workers can reach to each other, P2P Volume Streaming should:

  • Speed up volume streaming between workers
  • Reduce ATC's cpu/memory/network usages that spend on volume streaming

Corresponding baggeclaim part code change is concourse/baggageclaim#39

I have done a PoC. In the PoC, I run the 20 pipelines with the following code:

resources:
- name: timer
  type: time
  source:
    interval: 1m

jobs:
- name: test
  public: true
  plan:
  - get: timer
    trigger: true

  - task: t1
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      outputs:
      - name: out1
      run:
        path: sh
        args:
         - -exc
         - dd bs=1024 count=50000 </dev/urandom >out1/f1.bin

  - task: t2
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      inputs:
      - name: out1
      outputs:
      - name: out2
      run:
        path: sh
        args:
         - -exc
         - dd bs=1024 count=50000 </dev/urandom >out2/f2.bin
         - ls -l out1/

  - task: t3
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      inputs:
      - name: out2
      outputs:
      - name: out3
      run:
        path: sh
        args:
         - -exc
         - dd bs=1024 count=50000 </dev/urandom >out3/f3.bin
         - ls -l out2/

  - task: t4
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      inputs:
      - name: out3
      outputs:
      - name: out4
      run:
        path: sh
        args:
         - -exc
         - dd bs=1024 count=50000 </dev/urandom >out4/f4.bin
         - ls -l out3/

  - task: t5
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      inputs:
      - name: out4
      run:
        path: sh
        args:
         - -exc
         - ls -l out4/

All pipelines are triggered a 1-minute timer, and a pipeline contains 5 tasks, each task just generate a 50MB random binary file, and is used in next task.

My test cluster has 1 ATC node and 4 workers, using random container placement strategy, so that a lot of volume streaming would happen.

I ran the test without and with P2P mode each for ~40 minutes. The following metrics shows big performance improvement with P2P mode:

First, let's see build status. The two rounds of test should generate same number of builds. But we can see that, under P2P mode, the test generated more successful builds, which indicates that under P2P mode, build ran faster because of shorter volume streaming time.

build-status

Also, let's see volumes streamed. Both tests caused roughly same number of volume streaming.

volumes-streamed

Then let's difference of ATC cpu/memory/network usages.

web-cpu

web-memory-used

web-network

We can see that, ATC cpu/memory usages under P2P mode are just roughly 1/3 of non-P2P mode. And the usage curves under P2P mode are smoother and flat-ter, which indicates that ATC under P2P mode should be more stable.

As expected, as volume streaming bits not going through ATC, under P2P mode, ATC's network usage is only at KB level.

Changes proposed by this PR:

Notes to reviewer:

So far the code is still dirty, and tests have not been updated.

EDIT: I have cleaned up the code, so it's ready for review. Please ignore changes in go.mod, docker-compose.yml and Dockerfile. They ease my local tests, I'll revert them when review is done.

EDIT: I have cleaned up all of the code changes, and added test cases. Now this PR is ready for review.

NOTE: With this feature, worker version should be bumped, because two BC endpoints are added, workers must be redeployed, otherwise this feature won't work.

Release Note

  • Support P2P volume streaming directly between two workers instead of through the ATC.
    • This is an opt-in feature enabled with --enable-p2p-volume-streaming or env var $CONCOURSE_ENABLE_P2P_VOLUME_STREAMING on the web nodes. When this feature is enabled, --baggageclaim-bind-ip on workers should be set to 0.0.0.0 so that baggage claim can be accessed from another workers.
    • This should only be used for clusters where all workers can reach each other on the same local network.
    • Adds --baggageclaim-p2p-interface-name-pattern and --baggageclaim-p2p-interface-family to the worker command.

Contributor Checklist

Reviewer Checklist

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the
    BOSH and
    Helm packaging; otherwise, ignored for
    the integration
    tests

    (for example, if they are Garden configs that are not displayed in the
    --help text).

@aoldershaw
aoldershaw marked this pull request as draft October 21, 2020 03:00
@evanchaoli evanchaoli changed the title WIP: no review for now please WIP: P2P Volume Streaming Oct 28, 2020
@jmccann

jmccann commented Oct 28, 2020

Copy link
Copy Markdown
Contributor

Just wanted to say this caught my interest when looking from perspective of a cache that can be used across workers as requested in #1987 😄

@evanchaoli
evanchaoli force-pushed the p2p-streaming branch 2 times, most recently from 41b438c to 4f2d296 Compare November 2, 2020 03:12
@evanchaoli evanchaoli changed the title WIP: P2P Volume Streaming feat: P2P Volume Streaming Nov 2, 2020
@evanchaoli
evanchaoli marked this pull request as ready for review November 2, 2020 03:18
@evanchaoli
evanchaoli force-pushed the p2p-streaming branch 2 times, most recently from 58e0c1c to f7600e1 Compare November 7, 2020 13:29
@evanchaoli
evanchaoli force-pushed the p2p-streaming branch 3 times, most recently from 2aec6c8 to b7081fc Compare November 10, 2020 07:31
@evanchaoli

evanchaoli commented Nov 10, 2020 •

Copy link
Copy Markdown
Contributor Author

@taylorsilva This PR is ready for review. Code cleaned up and tests added. Please notice that, as two BC endpoints are added, worker version (currently 2.2) should be bumped.

@evanchaoli
evanchaoli force-pushed the p2p-streaming branch 2 times, most recently from 9e31501 to 35c1333 Compare November 10, 2020 09:16
@vito

vito commented Nov 10, 2020

Copy link
Copy Markdown
Contributor

Pretty dang cool! It sounds like so far this is opt-in and you have to make sure all your workers can reach each other?

I wonder if a future iteration could have workers specify their network somehow - maybe just a name to indicate which workers live in the same network. Or maybe this behavior could be tied to pools somehow? 🤔

Anyway this is awesome, thanks for working on it!

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as expected! Ran a simple job with each step running on a different worker. I added a log line in artifact_source so I could confirm that it used the p2pStreamTo().
image

I just have one nit about adding the tracing calls since streamTo has it. I'd like to keep parity on those functions and will probably help make it easier to get data on how fast p2p streaming is vs through the web node.

My docker-compose file for testing:

version: '3'

services:
  db:
    image: postgres:${POSTGRES_TAG:-latest}
    shm_size: 1gb
    ports:
    - 6543:5432
    environment:
      POSTGRES_DB: concourse
      POSTGRES_USER: dev
      POSTGRES_PASSWORD: dev

  web:
    build: .
    image: concourse/concourse:local
    volumes:
    - .:/src
    command: web
    depends_on: [db]
    ports:
    - 8080:8080
    environment:
      CONCOURSE_LOG_LEVEL: debug
      CONCOURSE_POSTGRES_HOST: db
      CONCOURSE_POSTGRES_USER: dev
      CONCOURSE_POSTGRES_PASSWORD: dev
      CONCOURSE_POSTGRES_DATABASE: concourse
      CONCOURSE_EXTERNAL_URL: http://localhost:8080
      CONCOURSE_ADD_LOCAL_USER: test:test,guest:guest
      CONCOURSE_MAIN_TEAM_LOCAL_USER: test
      CONCOURSE_CLUSTER_NAME: dev
      CONCOURSE_ENABLE_PIPELINE_INSTANCES: "true"
      CONCOURSE_ENABLE_ACROSS_STEP: "true"

  worker-1:
    build: .
    image: concourse/concourse:local
    command: worker
    privileged: true
    depends_on: [web]
    stop_signal: SIGUSR2
    environment:
      CONCOURSE_LOG_LEVEL: debug
      CONCOURSE_TSA_HOST: web:2222

      # avoid using loopbacks
      CONCOURSE_BAGGAGECLAIM_DRIVER: overlay

      # so we can reach Garden/Baggageclaim for debugging
      CONCOURSE_BIND_IP: 0.0.0.0
      CONCOURSE_BAGGAGECLAIM_BIND_IP: 0.0.0.0
      CONCOURSE_GARDEN_DNS_PROXY_ENABLE: "true"
      CONCOURSE_TAG: worker-1
      CONCOURSE_ENABLE_P2P_VOLUME_STREAMING: "true"

  worker-2:
    build: .
    image: concourse/concourse:local
    command: worker
    privileged: true
    depends_on: [web]
    stop_signal: SIGUSR2
    environment:
      CONCOURSE_LOG_LEVEL: debug
      CONCOURSE_TSA_HOST: web:2222

      # avoid using loopbacks
      CONCOURSE_BAGGAGECLAIM_DRIVER: overlay

      # so we can reach Garden/Baggageclaim for debugging
      CONCOURSE_BIND_IP: 0.0.0.0
      CONCOURSE_BAGGAGECLAIM_BIND_IP: 0.0.0.0
      CONCOURSE_GARDEN_DNS_PROXY_ENABLE: "true"
      CONCOURSE_TAG: worker-2
      CONCOURSE_ENABLE_P2P_VOLUME_STREAMING: "true"

Comment thread atc/worker/artifact_source.go Resolved
@evanchaoli

evanchaoli commented Nov 11, 2020 •

Copy link
Copy Markdown
Contributor Author

Pretty dang cool! It sounds like so far this is opt-in and you have to make sure all your workers can reach each other?

@vito In our deployments, all workers can reach each other, so I'll immediately enable this feature once it's available.

I have no idea with other deployments, so that I make this feature opt-in. If a cluster administrator knows that all workers can reach each other, then s/he can turn on this feature; otherwise this feature is by default off, innocent by doing nothing.

I wonder if a future iteration could have workers specify their network somehow - maybe just a name to indicate which workers live in the same network. Or maybe this behavior could be tied to pools somehow? 🤔

I have added two worker CLI options in baggage-claim https://github.com/concourse/baggageclaim/blob/v1.9.0/baggageclaimcmd/command.go#L29-L30, which allows to specify which network interface to use for p2p streaming, and IPv4 or v6 to use, which has been good enough for our deployments.

If some other deployments' network configuration is more complicated, we may enhance later. Or the user may contribute an enhancement. As the core function is there, such enhancement about configuration should be easy to do.

Tied to work pools? Could be a future option. I think potential enhancements could be:

  • ATC probes source and dest workers to see if they both support p2p streaming
  • When p2p stream fails, fall back to via-atc-streaming
  • Tied to worker pool
  • And so on ...

But they are not priorities for our deployments for now.

The other thing is, I'm just thinking loudly, once P2P streaming is there, for image fetching, if a worker has the required docker image, while the other worker doesn't have, p2p streaming images locally between workers should be cheaper than fetching it again from DockerHub (as well as other image registries). WDYT?

@evanchaoli

Copy link
Copy Markdown
Contributor Author

@taylorsilva I have added the tracing. Please hold on merge this PR for a few days even if you have no more comments. Let me run more tests locally, especially for rainy day cases, like source/target workers crashed during streaming. I'll let you know once my tests are done.

@aoldershaw

Copy link
Copy Markdown
Contributor

I wonder if a future iteration could have workers specify their network somehow - maybe just a name to indicate which workers live in the same network. Or maybe this behavior could be tied to pools somehow? 🤔

It doesn't need to block this PR, but I think having some notion of separate networks would be useful. I may be wrong, but I suspect we won't be able to enable this on either CI or hush-house because of our physical Darwin/Windows workers + team-specific external workers in hush-house, despite the fact that the vast majority of the workloads run on workers in the same network

Obviously there's no harm in not enabling it, but I'm excited to see the performance gains!

@evanchaoli

Copy link
Copy Markdown
Contributor Author

@taylorsilva @vito I have finished my tests. Yesterday I encountered a problem where builds hang up if p2p stream timed out. I tried to debug the issue, and found it hang up in retryhttp module:

goroutine 38229 [select]:
github.com/cenkalti/backoff.RetryNotify(0xc000b8ca30, 0x42e77e0, 0xc001941200, 0x0, 0x0, 0x0)
	/go/pkg/mod/github.com/cenkalti/[email protected]+incompatible/retry.go:60 +0x32c
github.com/cenkalti/backoff.Retry(0xc0011d0a30, 0x42e77e0, 0xc001941200, 0x0, 0x0)
	/go/pkg/mod/github.com/cenkalti/[email protected]+incompatible/retry.go:24 +0x50
github.com/concourse/retryhttp.(*RetryRoundTripper).RoundTrip(0xc000fb64c0, 0xc0018b5c00, 0x0, 0x0, 0x0)
	/go/pkg/mod/github.com/concourse/[email protected]/retry_round_tripper.go:55 +0x2a6

The I found that @vito seems to hit same problem and created a new version retryhttp v1.1.0. After bumping to v1.1.0, http timeout works properly now. So I added a new commit to bump retryhttp to v1.1.0.

@taylorsilva taylorsilva left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

@taylorsilva
taylorsilva merged commit cc6d4a1 into concourse:master Nov 12, 2020
taylorsilva added a commit that referenced this pull request Nov 17, 2020
This test started failing because the retryHttp package was bumped,
causing a change in behaviour. Now the test is stuck waiting for `fly
watch` to exit, whereas before it would exit after ~5mins

retryHttp was bumped in #6186

Existing issue that contains reproducible steps is
#3011

Signed-off-by: Taylor Silva <[email protected]>
@taylorsilva taylorsilva mentioned this pull request Nov 17, 2020
2 of 11 tasks
@aoldershaw aoldershaw changed the title feat: P2P Volume Streaming Experimental support for P2P Volume Streaming Jan 25, 2021
@aoldershaw aoldershaw added the release/undocumented This didn't warrant being documented or put in release notes. label Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement release/undocumented This didn't warrant being documented or put in release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants