mbonea-ewallet godwin
commited on
Commit
·
f4dfdc4
1
Parent(s):
d93cd62
possibly ready?
Browse files- App/Post/PostRoutes.py +5 -0
- App/modelInit.py +16 -4
- Dockerfile +1 -1
- docker-compose.yml +31 -31
- stress_test.py +13 -4
App/Post/PostRoutes.py
CHANGED
@@ -23,3 +23,8 @@ async def create_post(post: editPost):
|
|
23 |
async def create_post(post: getPost):
|
24 |
data = await Post.objects.get(id=post.id)
|
25 |
return {"code": 200, "message": "success", "payload": data.__dict__}
|
|
|
|
|
|
|
|
|
|
|
|
23 |
async def create_post(post: getPost):
|
24 |
data = await Post.objects.get(id=post.id)
|
25 |
return {"code": 200, "message": "success", "payload": data.__dict__}
|
26 |
+
|
27 |
+
@post_router.post("/post/delete_all")
|
28 |
+
async def create_post():
|
29 |
+
data = await Post.objects.delete()
|
30 |
+
return {"code": 200, "message": "success", "payload": data.__dict__}
|
App/modelInit.py
CHANGED
@@ -2,12 +2,24 @@ import databases
|
|
2 |
import orm
|
3 |
import psycopg2
|
4 |
|
5 |
-
#
|
6 |
-
#
|
7 |
-
#
|
|
|
|
|
|
|
8 |
database = databases.Database(
|
9 |
-
"postgresql+asyncpg://
|
10 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# databases = databases.Database(**args)
|
13 |
models = orm.ModelRegistry(database=database)
|
|
|
2 |
import orm
|
3 |
import psycopg2
|
4 |
|
5 |
+
# HOST=aws.connect.psdb.cloud
|
6 |
+
# USERNAME=kn9rzjlad1tw8bvojqg9
|
7 |
+
# PASSWORD=pscale_pw_hSBO8rcekvnQp74bezC9gjnShhAWgkJYUS8GjGdrBKn
|
8 |
+
# DATABASE=movie-website
|
9 |
+
|
10 |
+
|
11 |
database = databases.Database(
|
12 |
+
"postgresql+asyncpg://postgres:CW38stnBqQnCEHe@db.vqbjlhcywjisidxeipdg.supabase.co:5432/postgres"
|
13 |
)
|
14 |
+
# database = databases.Database(
|
15 |
+
# "postgresql+asyncpg://user:password@db:5432/mydatabase"
|
16 |
+
# )
|
17 |
+
|
18 |
+
# #mysql
|
19 |
+
# database = databases.Database(
|
20 |
+
# 'mysql+asyncmy://kn9rzjlad1tw8bvojqg9:pscale_pw_hSBO8rcekvnQp74bezC9gjnShhAWgkJYUS8GjGdrBKn@aws.connect.psdb.cloud/movie-website'
|
21 |
+
# ,)
|
22 |
+
|
23 |
|
24 |
# databases = databases.Database(**args)
|
25 |
models = orm.ModelRegistry(database=database)
|
Dockerfile
CHANGED
@@ -3,5 +3,5 @@ WORKDIR /usr/src/nginx
|
|
3 |
COPY . .
|
4 |
|
5 |
RUN python3 -m pip install -r requirements.txt
|
6 |
-
CMD uvicorn App.app:app --host 0.0.0.0 --workers
|
7 |
EXPOSE 8000
|
|
|
3 |
COPY . .
|
4 |
|
5 |
RUN python3 -m pip install -r requirements.txt
|
6 |
+
CMD uvicorn App.app:app --host 0.0.0.0 --workers 4
|
7 |
EXPOSE 8000
|
docker-compose.yml
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
version: '3'
|
2 |
|
3 |
services:
|
4 |
-
db:
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
grafana:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
app:
|
36 |
restart: always
|
37 |
build:
|
@@ -42,7 +42,7 @@ services:
|
|
42 |
- db
|
43 |
environment:
|
44 |
- DATABASE_URL=postgresql://user:password@db:5432/mydatabase
|
45 |
-
command: uvicorn App.app:app --host 0.0.0.0 --port 8000 --workers
|
46 |
|
47 |
|
48 |
|
|
|
1 |
version: '3'
|
2 |
|
3 |
services:
|
4 |
+
# db:
|
5 |
+
# image: postgres
|
6 |
+
# environment:
|
7 |
+
# POSTGRES_USER: user
|
8 |
+
# POSTGRES_PASSWORD: password
|
9 |
+
# POSTGRES_DB: mydatabase
|
10 |
+
# POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --no-local"
|
11 |
+
# TZ: UTC
|
12 |
+
# ports:
|
13 |
+
# - "5432:5432"
|
14 |
+
# volumes:
|
15 |
+
# - postgres_data:/var/lib/postgresql/data
|
16 |
+
# command: postgres -c max_connections=500 -c shared_buffers=1GB -c effective_cache_size=3GB -c maintenance_work_mem=512MB
|
17 |
|
18 |
+
# grafana:
|
19 |
+
# image: grafana/grafana:latest
|
20 |
+
# restart: always
|
21 |
+
# ports:
|
22 |
+
# - "3000:3000"
|
23 |
+
# environment:
|
24 |
+
# GF_AUTH_ANONYMOUS_ENABLED: "true"
|
25 |
+
# GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin"
|
26 |
+
# GF_AUTH_ANONYMOUS_ORG_NAME: "Main Org."
|
27 |
+
# GF_SECURITY_ADMIN_USER: user
|
28 |
+
# GF_SECURITY_ADMIN_PASSWORD: password
|
29 |
+
# DATABASE_TYPE: postgres
|
30 |
+
# DATABASE_HOST: db
|
31 |
+
# DATABASE_PORT: 5432
|
32 |
+
# DATABASE_NAME: mydatabase
|
33 |
+
# DATABASE_USER: user
|
34 |
+
# DATABASE_PASSWORD: password
|
35 |
app:
|
36 |
restart: always
|
37 |
build:
|
|
|
42 |
- db
|
43 |
environment:
|
44 |
- DATABASE_URL=postgresql://user:password@db:5432/mydatabase
|
45 |
+
command: uvicorn App.app:app --host 0.0.0.0 --port 8000 --workers 4
|
46 |
|
47 |
|
48 |
|
stress_test.py
CHANGED
@@ -1,23 +1,32 @@
|
|
1 |
import asyncio
|
2 |
import aiohttp
|
3 |
|
|
|
4 |
|
5 |
async def send_post_request(session,number=0):
|
6 |
async with session.post(
|
7 |
-
url="https://
|
8 |
-
json={
|
|
|
|
|
|
|
9 |
) as response:
|
10 |
response_text = await response.text()
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
async def send_post_requests_async():
|
15 |
async with aiohttp.ClientSession() as session:
|
16 |
tasks = []
|
17 |
-
for number in range(
|
18 |
tasks.append(asyncio.ensure_future(send_post_request(session,number)))
|
19 |
await asyncio.gather(*tasks)
|
20 |
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
asyncio.run(send_post_requests_async())
|
|
|
|
1 |
import asyncio
|
2 |
import aiohttp
|
3 |
|
4 |
+
analysis = {'failed':0,'passed':0}
|
5 |
|
6 |
async def send_post_request(session,number=0):
|
7 |
async with session.post(
|
8 |
+
url="https://app-mbonea-mjema.cloud.okteto.net/post/create",
|
9 |
+
json={
|
10 |
+
"content": {},
|
11 |
+
"recommendations": {}
|
12 |
+
}
|
13 |
) as response:
|
14 |
response_text = await response.text()
|
15 |
+
if response.status == 200:
|
16 |
+
analysis['passed'] += 1
|
17 |
+
print(f"Response from {number}: {response_text}")
|
18 |
+
else:
|
19 |
+
analysis['failed'] += 1
|
20 |
|
21 |
|
22 |
async def send_post_requests_async():
|
23 |
async with aiohttp.ClientSession() as session:
|
24 |
tasks = []
|
25 |
+
for number in range(1_000):
|
26 |
tasks.append(asyncio.ensure_future(send_post_request(session,number)))
|
27 |
await asyncio.gather(*tasks)
|
28 |
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
asyncio.run(send_post_requests_async())
|
32 |
+
print(analysis)
|