Comments (1)
Using GprcUser
instead of HttpUser
as written here helped to avoid deadlock. The resulting test/load/demo.py
:
from time import sleep
from locust import task
from langchain.vectorstores.milvus import Milvus
from pymilvus.grpc_gen.milvus_pb2_grpc import MilvusServiceStub
from villm.index.ChromaCollector import HuggingFaceEmbedder
from test.load.example import HOST, PORT
from test.load.quick import EMBEDDING_MODEL, COLLECTION
from test.load.GrpcUser import GrpcUser
class DemoTestUser(GrpcUser):
host = HOST
port = PORT
stub_class = MilvusServiceStub
def on_start(self):
print('creating embedder...')
embedder = HuggingFaceEmbedder(model_name = EMBEDDING_MODEL)
print('initializing milvus client...')
self.client = Milvus(
embedder.get_embedder(),
connection_args = {'host': HOST, 'port': PORT},
collection_name = COLLECTION
)
print('ready to make queries')
@task
def query(self):
print('starting task...')
sleep(2)
print('ending task...')
The contents of test/load/GrpcUser.py
:
import time
from typing import Any, Callable
import grpc
import grpc.experimental.gevent as grpc_gevent
from grpc_interceptor import ClientInterceptor
from locust import User
from locust.exception import LocustError
# patch grpc so that it uses gevent instead of asyncio
grpc_gevent.init_gevent()
class LocustInterceptor(ClientInterceptor):
def __init__(self, environment, *args, **kwargs):
super().__init__(*args, **kwargs)
self.env = environment
def intercept(
self,
method: Callable,
request_or_iterator: Any,
call_details: grpc.ClientCallDetails,
):
response = None
exception = None
start_perf_counter = time.perf_counter()
response_length = 0
try:
response = method(request_or_iterator, call_details)
response_length = response.result().ByteSize()
except grpc.RpcError as e:
exception = e
self.env.events.request.fire(
request_type="grpc",
name=call_details.method,
response_time=(time.perf_counter() - start_perf_counter) * 1000,
response_length=response_length,
response=response,
context=None,
exception=exception,
)
return response
class GrpcUser(User):
abstract = True
stub_class = None
def __init__(self, environment):
super().__init__(environment)
for attr_value, attr_name in ((self.host, "host"), (self.stub_class, "stub_class")):
if attr_value is None:
raise LocustError(f"You must specify the {attr_name}.")
self._channel = grpc.insecure_channel(self.host)
interceptor = LocustInterceptor(environment=environment)
self._channel = grpc.intercept_channel(self._channel, interceptor)
self.stub = self.stub_class(self._channel)
from locust.
Related Issues (20)
- User Classes with Empty Tasks Results in TypeError: 'NoneType' object is not iterable HOT 2
- how the requests # being counted in my test case ? HOT 1
- Fixed RPS load test HOT 3
- HTML Report cannot be displayed HOT 5
- The Charts presentation in the report downloaded by locust is problematic HOT 3
- How to view the load of the master when starting in a distributed manner HOT 1
- Incorrect RPS reported in statistics and graphs (distributed mode) HOT 13
- Load shapes not removing users when user_classes changes HOT 4
- The exit code for controlling the locust process has a bug HOT 3
- Can the data in the csv be statistically averaged according to the current number of users, rather than the average from the start of the pressure test to the present? HOT 11
- Show the reset button even after stopping a test HOT 1
- `SequentialTaskSet` handles task weights in an inconsistent way
- Use `itertools.cycle` in `SequentialTaskSet`
- ConnectionRefusedError and ConnectionResetError judgment abnormal HOT 3
- Exception: Tried to stop User in an unexpected state: stopping. This should never happen. HOT 2
- Specifying users in CLI should use a keyword parameter HOT 2
- Can interfaces under the same task support collapsing and show the overall data HOT 2
- How to reset the report data without stopping the stress test? Is there a similar interface? HOT 2
- Log a warning if getting locustfile from master takes more than 60s
- locust/webui/dist/index.html script errors. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from locust.