Skip to content

Commit

Permalink
fix concurrency issue
Browse files Browse the repository at this point in the history
Signed-off-by: pandyamarut <[email protected]>
  • Loading branch information
pandyamarut committed Jan 6, 2025
1 parent 95109c3 commit e7569c9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@
from engine import SGlangEngine
from utils import process_response
import runpod
import os

# Initialize the engine
engine = SGlangEngine()
engine.start_server()
engine.wait_for_server()


def get_max_concurrency(default=50):
"""
Returns the maximum concurrency value.
By default, it uses 50 unless the 'MAX_CONCURRENCY' environment variable is set.
Args:
default (int): The default concurrency value if the environment variable is not set.
Returns:
int: The maximum concurrency value.
"""
return int(os.getenv('MAX_CONCURRENCY', default))



async def async_handler(job):
"""Handle the requests asynchronously."""
job_input = job["input"]
Expand Down Expand Up @@ -41,4 +57,4 @@ async def async_handler(job):
else:
yield {"error": f"Generate request failed with status code {response.status_code}", "details": response.text}

runpod.serverless.start({"handler": async_handler, "return_aggregate_stream": True})
runpod.serverless.start({"handler": async_handler, "concurrency_modifier": get_max_concurrency, "return_aggregate_stream": True})

0 comments on commit e7569c9

Please sign in to comment.