Home > other >  Locust collection after the set up, run successfully, but there is no waiting for monitoring found t
Locust collection after the set up, run successfully, but there is no waiting for monitoring found t

Time:05-03

The import locust
# the from gevent. _semaphore import Semaphore
Import gevent # collection point: multi-user concurrent operation at the same time (monitoring platform to set the number of users, such as 100, a total of 100 users, add 5 per second, will wait until 100 only when user send request together,

# 3, set point
All_locusts_spawned=gevent. _semaphore. Semaphore () # collection class instantiation
All_locusts_spawned. Acquire () # lock

Def on_hatch_complete (* * kwargs) :
# all_locusts_spawned. Release () releases the lock

# hanging on to locust hooks (all instances of locust produce complete trigger)
Old version: # locust. Events. Hatch_complete +=on_hatch_complete
Locust. Events. Spawning_complete. Add_listener (on_hatch_complete ())


# 2, the main function calls the task of class, the class name can be arbitrarily
The class UserBehavior2 (locust. The TaskSet) :
# 1. The constructor, can put the variable
Def on_start (self) :
The self. The index=0
Print ("======onstart begin: ")
All_locusts_spawned. Wait () # collection point: create hook method
Print ("======onstart end: ")


@ locust. Task
Def test_visit (self) :
Url="/getJoke? Page="+ STR (self) parent) share_data [2]) +" & amp; The count="+ STR (self. Index + 2)
Res=self. Client. Get (url, name='getJoke paging query')
Res=res. Text
# 1. Inheritance locust. HttpUser class as the main function, equivalent to the main, class names can be arbitrary
The class WebSiteUser232323 (locust. HttpUser) : # locust. HttpLocust
Measured website domain name # 1.
The host='https://api.apiopen.top'

# 3. The performance test task types: login or register
The tasks=[UserBehavior2] # call which task

# 4. The waiting time is set
Wait_time=locust. Between (3, 7)
# locust -f locustS. Py - host=https://www.baidu.com localhost: 8089


  • Related