-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update server.cpp example with correct startup sequence #6739
base: master
Are you sure you want to change the base?
Conversation
The HTTP listener start and the health API endpoint are moved before the model loading starts, hence the server can correctly report is loading the model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, all API endpoints must be registered before server start listening (svr->listen_after_bind()
in this case), so I'm not convinced by this change, which registers /health
before all other endpoints and the rest being registered after model loaded. During the model load, all other endpoints will throw 404 not found error which is not correct (it should be 503 Service Unavailable)
Furthermore, this change requires main thread to call svr
to register new endpoints after it is spawned into new thread. This will make svr
not thread-safe.
In any cases, it will be more logical to call ctx_server.load_model(params)
only after all endpoints are registered. Additionally, we can add a middleware to throw 503 if the model is not yet loaded.
Binding them before doesn't work, the model must be loaded. I will amend it registering the other endpoints with a static 503 answer before listening and re-registering them later once the model is loaded. |
You are right I didn't check this. |
This comment was marked as off-topic.
This comment was marked as off-topic.
The reference to Another thing to add is inside |
- Moved endpoints registration before HTTP listener starts - Endpoints are returning the correct error when the model is loading or failed to load - Server is exiting if failed to bind the port
Can you please check it again and let me know? The empty_json_model() is just a leftover of course. What I'm wondering is if the middleware should report error 500 also for the static pages. Thanks! |
If we can return the static pages while the model is loading, this is fine. |
@ngxson |
Co-authored-by: Xuan Son Nguyen <thichthat@gmail.com>
The HTTP listener start and the health API endpoint are moved before the model loading starts, hence the server can correctly report is loading the model