Skip to content

server : refactor middleware and /health endpoint - #9056

Merged
ngxson merged 6 commits into
ggml-org:masterfrom
ngxson:wsn/server_health_non_blocking
Aug 16, 2024
Merged

server : refactor middleware and /health endpoint#9056
ngxson merged 6 commits into
ggml-org:masterfrom
ngxson:wsn/server_health_non_blocking

Conversation

@ngxson

@ngxson ngxson commented Aug 16, 2024

Copy link
Copy Markdown
Collaborator

/health endpoint

In the beginning, /health endpoint was used to retrieve slots state. That was because at the time, /completions endpoint returns an error if there is no slot available. Therefore, /health was used to allow the application to wait until one slot is available.

Nowadays, the server now can queue (defer) the request if no slots is available. /health is used by docker for health checking. This is now become a problem when the server is busy doing a long task, /health can timeout. On HF inference endpoint, this causes the container to be in unhealthy state, which triggers a force restart.

Therefore, I propose a cleaner usage:

  • GET /health is now purely used to report actual health
  • GET /slots can be used as a replacement to get slot state

As a consequence, /health?fail_on_no_slot=1 is also moved to /slots?fail_on_no_slot=1 (for compatibility, we keep this option)

Refactor middleware

Some repeated code blocks, for example setting Access-Control-Allow-Origin, is now moved to middleware.

Middleware now also responsible to return error if the server is not yet ready:

When the server starts, if the model is being loaded, accessing to any endpoint will result in 503 error code:

image

Behavior on loading model failed

If model fails to load (for example, file does not exist), the server will simply exit with status code 1. This resolves #7787 where user reports that loading invalid model causes the server to crash.

image


Comment thread examples/server/server.cpp Outdated
ngxson and others added 2 commits August 16, 2024 11:01
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
@github-actions github-actions Bot added the python python script changes label Aug 16, 2024
@mcharytoniuk

Copy link
Copy Markdown
Contributor

I started a discussion thread related to this issue, please take a look: #9276

@ngxson ngxson added the breaking change Changes that break ABIs, APIs, file formats, or other forms of backwards compatibility. label Sep 2, 2024
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Nov 15, 2024
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Nov 18, 2024
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request Feb 25, 2025
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
phibya pushed a commit to ziee-ai/llama.cpp that referenced this pull request May 29, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
* server : refactor middleware and /health endpoint

* move "fail_on_no_slot" to /slots

* Update examples/server/server.cpp

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix server tests

* fix CI

* update server docs

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Changes that break ABIs, APIs, file formats, or other forms of backwards compatibility. examples python python script changes server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: investigate cleaner exception handling for server/server.cpp

3 participants