-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Support HTTP2 server #21700
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
Merged
Merged
Support HTTP2 server #21700
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2d6c415
support http2
ispobock 8a1783e
add test
ispobock 585c9af
Update python/sglang/srt/entrypoints/http_server.py
ispobock 830bcd7
Merge branch 'main' into http2-server
ispobock 34b188a
Merge branch 'main' into http2-server
ispobock 5bdec33
update
ispobock 1222a87
update
ispobock 51db219
update
ispobock 1f12a4d
Merge branch 'main' into http2-server
ispobock 62b18f0
Merge branch 'main' into http2-server
ispobock 2114f9e
Merge branch 'main' into http2-server
ispobock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
test/registered/openai_server/basic/test_http2_server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| """ | ||
| Test HTTP/2 server (Granian) with basic OpenAI-compatible endpoints. | ||
|
|
||
| Verifies that --enable-http2 launches successfully and serves requests | ||
| via both HTTP/1.1 and HTTP/2 (h2c). | ||
| """ | ||
|
|
||
| import subprocess | ||
| import unittest | ||
|
|
||
| import requests | ||
|
|
||
| from sglang.srt.utils import kill_process_tree | ||
| from sglang.test.ci.ci_register import register_cuda_ci | ||
| from sglang.test.test_utils import ( | ||
| DEFAULT_SMALL_MODEL_NAME_FOR_TEST, | ||
| DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH, | ||
| DEFAULT_URL_FOR_TEST, | ||
| CustomTestCase, | ||
| popen_launch_server, | ||
| ) | ||
|
|
||
| try: | ||
| import granian # noqa: F401 | ||
|
|
||
| _HAS_GRANIAN = True | ||
| except ImportError: | ||
| _HAS_GRANIAN = False | ||
|
|
||
| register_cuda_ci(est_time=120, suite="stage-b-test-small-1-gpu") | ||
|
|
||
|
|
||
| @unittest.skipUnless(_HAS_GRANIAN, "granian not installed (pip install sglang[http2])") | ||
| class TestHTTP2Server(CustomTestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST | ||
| cls.base_url = DEFAULT_URL_FOR_TEST | ||
| cls.process = popen_launch_server( | ||
| cls.model, | ||
| cls.base_url, | ||
| timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH, | ||
| other_args=["--enable-http2"], | ||
| ) | ||
|
|
||
| @classmethod | ||
| def tearDownClass(cls): | ||
| kill_process_tree(cls.process.pid) | ||
|
|
||
| def test_health(self): | ||
| resp = requests.get(f"{self.base_url}/health") | ||
| self.assertEqual(resp.status_code, 200) | ||
|
|
||
| def test_get_model_info(self): | ||
| resp = requests.get(f"{self.base_url}/get_model_info") | ||
| self.assertEqual(resp.status_code, 200) | ||
| self.assertIn("model_path", resp.json()) | ||
|
|
||
| def test_completion(self): | ||
| resp = requests.post( | ||
| f"{self.base_url}/v1/completions", | ||
| json={ | ||
| "model": self.model, | ||
| "prompt": "The capital of France is", | ||
| "max_tokens": 8, | ||
| "temperature": 0, | ||
| }, | ||
| ) | ||
| self.assertEqual(resp.status_code, 200) | ||
| data = resp.json() | ||
| self.assertIn("choices", data) | ||
| self.assertGreater(len(data["choices"][0]["text"]), 0) | ||
|
|
||
| def test_chat_completion(self): | ||
| resp = requests.post( | ||
| f"{self.base_url}/v1/chat/completions", | ||
| json={ | ||
| "model": self.model, | ||
| "messages": [{"role": "user", "content": "Say hello"}], | ||
| "max_tokens": 16, | ||
| "temperature": 0, | ||
| }, | ||
| ) | ||
| self.assertEqual(resp.status_code, 200) | ||
| data = resp.json() | ||
| self.assertIn("choices", data) | ||
| self.assertGreater(len(data["choices"][0]["message"]["content"]), 0) | ||
|
|
||
| def test_h2c_with_curl(self): | ||
| """Verify the server actually speaks HTTP/2 via h2c.""" | ||
| result = subprocess.run( | ||
| [ | ||
| "curl", | ||
| "--http2-prior-knowledge", | ||
| "-s", | ||
| "-o", | ||
| "/dev/null", | ||
| "-w", | ||
| "%{http_version}", | ||
| f"{self.base_url}/health", | ||
| ], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=10, | ||
| ) | ||
| self.assertEqual( | ||
| result.stdout.strip(), "2", "Server should respond with HTTP/2" | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main(verbosity=3) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.