Skip to content

Instantly share code, notes, and snippets.

@densumesh
Last active June 26, 2024 17:20
Show Gist options
  • Save densumesh/c04938b8f38ba64ff60c55ed06d2c0fb to your computer and use it in GitHub Desktop.
Save densumesh/c04938b8f38ba64ff60c55ed06d2c0fb to your computer and use it in GitHub Desktop.
import asyncio
import aiohttp
import dotenv
import os
import time
import random
dotenv.load_dotenv()
base_url = os.getenv("TRIEVE_BASE_URL")
queries = [
"How to cook a turkey",
"Christmas gift ideas 2021",
"Best coffee shops near me",
"Keto diet recipes",
"How to get a passport",
"Closest gas station",
"Directions to Central Park New York",
"Taylor Swift latest album",
"Home workout routines",
"2022 Oscar nominations",
"Top-rated waterproof mascaras",
"Nearby hiking trails",
"How to cure a hangover",
"Easy DIY crafts for kids",
"Best car insurance companies",
"Symptoms of Covid-19",
"How to lose belly fat fast",
"Home remedies for sore throat",
"10-day weather forecast",
"Vegan meal prep ideas",
"Best TV shows on Netflix",
"Places to visit in Paris",
"Affordable wedding dress",
"How to train a puppy",
"High protein vegetarian foods",
"Best new mobile games",
"How to invest in stocks",
"University rankings in the US",
"Job interview tips",
"COVID-19 travel restrictions",
"Easy Christmas cookie recipes",
"Health benefits of green tea",
"How to write a resume",
"How to tie a tie",
"Where to get a COVID-19 vaccine",
"How to vote in the election",
"Symptoms of anxiety",
"Best fantasy books of all time",
"Top educational apps for kids",
"How does Bitcoin work",
"How to remove makeup properly",
"Free online photography courses",
"Ways to reduce carbon footprint",
"Exercises for lower back pain",
"Symptoms of dehydration",
"How to host a virtual event",
"How to declutter your home",
"Best digital marketing strategies",
"Samsung Galaxy S21 review",
"Anti-aging skincare routine",
"How to clean a laptop",
"Upcoming concerts near me",
"How to apply for a mortgage",
"Best selling books 2021",
"Electric car models",
"How to improve SEO",
"Yoga poses for beginners",
"Best dog breed for apartments",
"Local movie theatre showtimes",
"How to save money",
"Mental health resources",
"Home decor trends 2022",
"Learning coding basics",
"Local recycling drop-off locations",
"Tips for growing indoor plants",
"How to prevent hair loss",
"Kids activities during quarantine",
"Most comfortable mattresses",
"Fast food nutrition facts",
"Online safety tips for kids",
"How to meditate effectively",
"Latest Air Jordan release",
"Cultural festivals in India",
"How to start a podcast",
"Emergency roadside assistance",
"Order pizza near me",
"How to learn Spanish",
"Non-alcoholic cocktail recipes",
"Relaxing sounds for sleep",
"The history of the Internet",
"Best laptops for students",
"Most popular TikTok challenges",
"How to make homemade candles",
"Best audio books for road trips",
"Restaurants with outdoor seating",
"How to knit a sweater",
"Women’s World Cup 2023",
"How to play chess",
"How to start a small business",
"Weekend getaways in California",
"High speed internet providers",
"How to fix a leaky faucet",
"Popular diet trends 2022",
"Best charities to donate to",
"How to avoid phishing scams",
"How to use Photoshop",
"Easy-to-make Halloween costumes",
"Flight tickets to Hawaii",
"Ways to increase productivity",
"Designing a small kitchen space",
]
print(len(queries))
search_types = ["semantic", "fulltext", "hybrid"]
headers = {
"Authorization": os.getenv("TRIEVE_API_KEY"),
"TR-Dataset": os.getenv("TRIEVE_DATASET_ID"),
}
# Function to send a single request
async def send_request(session: aiohttp.ClientSession):
query = random.choice(queries)
search_type = random.choice(search_types)
data = {
"query": query,
"search_type": search_type,
}
start_time = time.perf_counter()
async with session.post(
f"{base_url}/api/chunk/search", headers=headers, json=data
) as response:
end_time = time.perf_counter()
request_time = end_time - start_time
return response.status, request_time
# Function to issue multiple requests concurrently
async def issue_requests_concurrently(num_requests):
async with aiohttp.ClientSession() as session:
tasks = [send_request(session) for _ in range(num_requests)]
results = await asyncio.gather(*tasks)
return results
# Main function to run the async requests
def main():
num_requests_at_once = 300
iterations = 20
for i in range(iterations):
print(f"Iteration {i + 1}")
results = asyncio.run(issue_requests_concurrently(num_requests_at_once))
# Print the results
if len([result for result in results if result[0] != 200]) > 0:
print(f"Request failed")
else:
print(
f"All requests succeeded. Average response time: {sum(result[1] for result in results) / len(results)}ms"
)
if __name__ == "__main__":
main()
@skeptrunedev
Copy link

Random search queries:

How to cook a turkey
Christmas gift ideas 2021
Best coffee shops near me
Keto diet recipes
How to get a passport
Closest gas station
Directions to Central Park New York
Taylor Swift latest album
Home workout routines
2022 Oscar nominations
Top-rated waterproof mascaras
Nearby hiking trails
How to cure a hangover
Easy DIY crafts for kids
Best car insurance companies
Symptoms of Covid-19
How to lose belly fat fast
Home remedies for sore throat
10-day weather forecast
Vegan meal prep ideas
Best TV shows on Netflix
Places to visit in Paris
Affordable wedding dress
How to train a puppy
High protein vegetarian foods
Best new mobile games
How to invest in stocks
University rankings in the US
Job interview tips
COVID-19 travel restrictions
Easy Christmas cookie recipes
Health benefits of green tea
How to write a resume
How to tie a tie
Where to get a COVID-19 vaccine
How to vote in the election
Symptoms of anxiety
Best fantasy books of all time
Top educational apps for kids
How does Bitcoin work
How to remove makeup properly
Free online photography courses
Ways to reduce carbon footprint
Exercises for lower back pain
Symptoms of dehydration
How to host a virtual event
How to declutter your home
Best digital marketing strategies
Samsung Galaxy S21 review
Anti-aging skincare routine
How to clean a laptop
Upcoming concerts near me
How to apply for a mortgage
Best selling books 2021
Electric car models
How to improve SEO
Yoga poses for beginners
Best dog breed for apartments
Local movie theatre showtimes
How to save money
Mental health resources
Home decor trends 2022
Learning coding basics
Local recycling drop-off locations
Tips for growing indoor plants
How to prevent hair loss
Kids activities during quarantine
Most comfortable mattresses
Fast food nutrition facts
Online safety tips for kids
How to meditate effectively
Latest Air Jordan release
Cultural festivals in India
How to start a podcast
Emergency roadside assistance
Order pizza near me
How to learn Spanish
Non-alcoholic cocktail recipes
Relaxing sounds for sleep
The history of the Internet
Best laptops for students
Most popular TikTok challenges
How to make homemade candles
Best audio books for road trips
Restaurants with outdoor seating
How to knit a sweater
Women’s World Cup 2023
How to play chess
How to start a small business
Weekend getaways in California
High speed internet providers
How to fix a leaky faucet
Popular diet trends 2022
Best charities to donate to
How to avoid phishing scams
How to use Photoshop
Easy-to-make Halloween costumes
Flight tickets to Hawaii
Ways to increase productivity 
Designing a small kitchen space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment