MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / get_request

Function get_request

benchmarks/quick_benchmark.py:110–150  ·  view source on GitHub ↗

Asynchronously generates requests at a specified rate with OPTIONAL burstiness. Args: input_requests: A list of input requests, each represented as a SampleRequest. request_rate: The rate at which requests are generated (requests/s). burs

(
    input_requests: list[SampleRequest],
    request_rate: float,
    burstiness: float = 1.0,
)

Source from the content-addressed store, hash-verified

108
109
110async def get_request(
111 input_requests: list[SampleRequest],
112 request_rate: float,
113 burstiness: float = 1.0,
114) -> AsyncGenerator[SampleRequest, None]:
115 """
116 Asynchronously generates requests at a specified rate
117 with OPTIONAL burstiness.
118
119 Args:
120 input_requests:
121 A list of input requests, each represented as a SampleRequest.
122 request_rate:
123 The rate at which requests are generated (requests/s).
124 burstiness (optional):
125 The burstiness factor of the request generation.
126 Only takes effect when request_rate is not inf.
127 Default value is 1, which follows a Poisson process.
128 Otherwise, the request intervals follow a gamma distribution.
129 A lower burstiness value (0 < burstiness < 1) results
130 in more bursty requests, while a higher burstiness value
131 (burstiness > 1) results in a more uniform arrival of requests.
132 """
133 input_requests: Iterable[SampleRequest] = iter(input_requests)
134
135 # Calculate scale parameter theta to maintain the desired request_rate.
136 assert burstiness > 0, f"A positive burstiness factor is expected, but given {burstiness}."
137 theta = 1.0 / (request_rate * burstiness)
138
139 for request in input_requests:
140 yield request
141
142 if request_rate == float("inf"):
143 # If the request rate is infinity, then we don't need to wait.
144 continue
145
146 # Sample the request interval from the gamma distribution.
147 # If burstiness is 1, it follows exponential distribution.
148 interval = np.random.gamma(shape=burstiness, scale=theta)
149 # The next request will be sent after the interval.
150 await asyncio.sleep(interval)
151
152
153def calculate_metrics(

Callers 1

benchmarkFunction · 0.70

Calls 1

sleepMethod · 0.45

Tested by

no test coverage detected