InfoGrab DocsInfoGrab Docs

Workhorse 핸들러

요약

Rails에서 긴 HTTP 요청을 효율적으로 처리하는 것은 어렵습니다. %%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails

Rails에서 긴 HTTP 요청을 효율적으로 처리하는 것은 어렵습니다. 이러한 요청은 메모리 비효율적(파일 업로드)이거나, 더 짧은 타임아웃(예: Puma 서버의 60초 타임아웃) 때문에 아예 처리가 불가능합니다. Workhorse는 많은 수의 긴 HTTP 요청을 효율적으로 처리할 수 있습니다. Workhorse는 모든 HTTP 요청을 가로채는 프록시 역할을 하며, 요청을 변경 없이 전달하거나 추가 로직을 수행하여 직접 처리합니다.

인젝터#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails

Client->>+Workhorse: Request
Workhorse->>+Rails: Propagate the request as-is
Rails-->>-Workhorse: Respond with a special header that contains instructions for proceeding with the request
Workhorse-->>Client: Response

예시: Git blob 전송#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails participant Gitaly

Client->>+Workhorse: HTTP Request for a blob
Workhorse->>+Rails: Propagate the request as-is
Rails-->>-Workhorse: Respond with a git-blob:{encoded_data} header
Workhorse->>+Gitaly: BlobService.GetBlob gRPC request
Gitaly-->>-Workhorse: BlobService.GetBlob gRPC request
Workhorse-->>Client: Stream the data

GitLab Rails가 요청을 처리하는 방법#

Workhorse가 헤더를 처리하는 방법#

예시: 파일 전송#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails participant Object Storage

Client->>+Workhorse: HTTP Request for a file
Workhorse->>+Rails: Propagate the request as-is
Rails-->>-Workhorse: Respond with a send-url:{encoded_data} header
Workhorse->>+Object Storage: Request for a file
Object Storage-->>-Workhorse: Stream the data
Workhorse-->>Client: Stream the data

사전 인가 요청#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails participant Object Storage

Client->>+Workhorse: PUT /artifacts/uploads
Note right of Rails: Append `/authorize` to the original URL and call Rails for an Auth check
Workhorse->>+Rails: GET /artifacts/uploads/authorize
Rails-->>-Workhorse: Authorized successfully

Client->>+Workhorse: Stream the file content
Workhorse->>+Object Storage: Upload the file
Object Storage-->>-Workhorse: Success

Workhorse->>+Rails: Finalize the request
Note right of Rails: Workhorse calls the original URL to create a database record
Rails-->>-Workhorse: Finalized successfully
Workhorse-->>Client: Uploaded successfully

Git over HTTP(S)#

Workhorse는 Git HTTP 프로토콜 요청을 처리하여 Git over HTTP(S)를 가속화합니다. 예를 들어, Git push/pull은 대량의 데이터를 처리해야 할 수 있습니다. 이 데이터를 GitLab Rails를 통해 전송하지 않도록, Workhorse는 GitLab Rails에 대한 인가 확인만 수행하고, 이후 Gitaly에 직접 gRPC 요청을 수행하여 Gitaly에서 Git 클라이언트로 데이터를 스트리밍합니다.

Git pull#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Git on client participant Workhorse participant Rails participant Gitaly

Note left of Git on client: git clone/fetch Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-upload-pack Workhorse->>+Rails: GET Repositories::GitHttpController#info_refs Note right of Rails: Access check/Log activity Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.InfoRefsUploadPack gRPC request Gitaly -->>-Workhorse: SmartHTTPService.InfoRefsUploadPack gRPC response Workhorse-->>-Git on client: send info-refs response Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-upload-pack Workhorse->>+Rails: GET Repositories::GitHttpController#git_receive_pack Note right of Rails: Access check/Update statistics Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.PostUploadPackWithSidechannel gRPC request Gitaly -->>-Workhorse: SmartHTTPService.PostUploadPackWithSidechannel gRPC response Workhorse-->>-Git on client: send response

Git push#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Git on client participant Workhorse participant Rails participant Gitaly

Note left of Git on client: git push Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-receive-pack Workhorse->>+Rails: GET Repositories::GitHttpController#info_refs Note right of Rails: Access check/Log activity Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.InfoRefsReceivePack gRPC request Gitaly -->>-Workhorse: SmartHTTPService.InfoRefsReceivePack gRPC response Workhorse-->>-Git on client: send info-refs response Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-receive-pack Workhorse->>+Rails: GET Repositories::GitHttpController#git_receive_pack Note right of Rails: Access check/Update statistics Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.PostReceivePackWithSidechannel gRPC request Gitaly -->>-Workhorse: SmartHTTPService.PostReceivePackWithSidechannel gRPC response Workhorse-->>-Git on client: send response

Workhorse 핸들러

GitLab v19.1
원문 보기
요약

Rails에서 긴 HTTP 요청을 효율적으로 처리하는 것은 어렵습니다. %%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails

Rails에서 긴 HTTP 요청을 효율적으로 처리하는 것은 어렵습니다. 이러한 요청은 메모리 비효율적(파일 업로드)이거나, 더 짧은 타임아웃(예: Puma 서버의 60초 타임아웃) 때문에 아예 처리가 불가능합니다. Workhorse는 많은 수의 긴 HTTP 요청을 효율적으로 처리할 수 있습니다. Workhorse는 모든 HTTP 요청을 가로채는 프록시 역할을 하며, 요청을 변경 없이 전달하거나 추가 로직을 수행하여 직접 처리합니다.

인젝터#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails

Client->>+Workhorse: Request
Workhorse->>+Rails: Propagate the request as-is
Rails-->>-Workhorse: Respond with a special header that contains instructions for proceeding with the request
Workhorse-->>Client: Response

예시: Git blob 전송#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails participant Gitaly

Client->>+Workhorse: HTTP Request for a blob
Workhorse->>+Rails: Propagate the request as-is
Rails-->>-Workhorse: Respond with a git-blob:{encoded_data} header
Workhorse->>+Gitaly: BlobService.GetBlob gRPC request
Gitaly-->>-Workhorse: BlobService.GetBlob gRPC request
Workhorse-->>Client: Stream the data

GitLab Rails가 요청을 처리하는 방법#

Workhorse가 헤더를 처리하는 방법#

예시: 파일 전송#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails participant Object Storage

Client->>+Workhorse: HTTP Request for a file
Workhorse->>+Rails: Propagate the request as-is
Rails-->>-Workhorse: Respond with a send-url:{encoded_data} header
Workhorse->>+Object Storage: Request for a file
Object Storage-->>-Workhorse: Stream the data
Workhorse-->>Client: Stream the data

사전 인가 요청#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Client participant Workhorse participant Rails participant Object Storage

Client->>+Workhorse: PUT /artifacts/uploads
Note right of Rails: Append `/authorize` to the original URL and call Rails for an Auth check
Workhorse->>+Rails: GET /artifacts/uploads/authorize
Rails-->>-Workhorse: Authorized successfully

Client->>+Workhorse: Stream the file content
Workhorse->>+Object Storage: Upload the file
Object Storage-->>-Workhorse: Success

Workhorse->>+Rails: Finalize the request
Note right of Rails: Workhorse calls the original URL to create a database record
Rails-->>-Workhorse: Finalized successfully
Workhorse-->>Client: Uploaded successfully

Git over HTTP(S)#

Workhorse는 Git HTTP 프로토콜 요청을 처리하여 Git over HTTP(S)를 가속화합니다. 예를 들어, Git push/pull은 대량의 데이터를 처리해야 할 수 있습니다. 이 데이터를 GitLab Rails를 통해 전송하지 않도록, Workhorse는 GitLab Rails에 대한 인가 확인만 수행하고, 이후 Gitaly에 직접 gRPC 요청을 수행하여 Gitaly에서 Git 클라이언트로 데이터를 스트리밍합니다.

Git pull#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Git on client participant Workhorse participant Rails participant Gitaly

Note left of Git on client: git clone/fetch Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-upload-pack Workhorse->>+Rails: GET Repositories::GitHttpController#info_refs Note right of Rails: Access check/Log activity Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.InfoRefsUploadPack gRPC request Gitaly -->>-Workhorse: SmartHTTPService.InfoRefsUploadPack gRPC response Workhorse-->>-Git on client: send info-refs response Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-upload-pack Workhorse->>+Rails: GET Repositories::GitHttpController#git_receive_pack Note right of Rails: Access check/Update statistics Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.PostUploadPackWithSidechannel gRPC request Gitaly -->>-Workhorse: SmartHTTPService.PostUploadPackWithSidechannel gRPC response Workhorse-->>-Git on client: send response

Git push#

%%{init: { "fontFamily": "GitLab Sans" }}%% sequenceDiagram participant Git on client participant Workhorse participant Rails participant Gitaly

Note left of Git on client: git push Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-receive-pack Workhorse->>+Rails: GET Repositories::GitHttpController#info_refs Note right of Rails: Access check/Log activity Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.InfoRefsReceivePack gRPC request Gitaly -->>-Workhorse: SmartHTTPService.InfoRefsReceivePack gRPC response Workhorse-->>-Git on client: send info-refs response Git on client->>+Workhorse: GET /foo/bar.git/info/refs?service=git-receive-pack Workhorse->>+Rails: GET Repositories::GitHttpController#git_receive_pack Note right of Rails: Access check/Update statistics Rails-->>Workhorse: 200 OK, Gitlab::Workhorse.git_http_ok Workhorse->>+Gitaly: SmartHTTPService.PostReceivePackWithSidechannel gRPC request Gitaly -->>-Workhorse: SmartHTTPService.PostReceivePackWithSidechannel gRPC response Workhorse-->>-Git on client: send response