Skip to content

Commit

Permalink
Add: A benchmark case with python httpx for non reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
ishkhan42 committed Sep 7, 2023
1 parent 92e24ea commit f31a688
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/login/jsonrpc_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import httpx
import os
import json
import errno
Expand Down Expand Up @@ -182,6 +183,28 @@ def recv(self):
return self.response.json


class CaseTLSNoReuseX:

def __init__(self, uri: str = '127.0.0.1', port: int = 8545, identity: int = PROCESS_ID) -> None:
self.identity = identity
self.url = f'https://{uri}:{port}/'

def __call__(self, *, a: Optional[int] = None, b: Optional[int] = None) -> int:

with httpx.Client(verify=False) as client:
a = random.randint(1, 1000) if a is None else a
b = random.randint(1, 1000) if b is None else b
jsonrpc = {"jsonrpc": "2.0", "id": self.identity,
"method": "validate_session", "params": {"user_id": a, "session_id": b}}
result = client.post(
f'{self.url}', json=jsonrpc,
headers={"Connection": "close"},
)
result = result.text
c = False if result == 'false' else True
return c


class CaseTCPHTTP:
"""JSON-RPC Client that operates directly over TCP/IPv4 stack, with HTTP"""

Expand Down

0 comments on commit f31a688

Please sign in to comment.