Skip to content

Instantly share code, notes, and snippets.

@mn-48
Created March 18, 2025 05:45
Show Gist options
  • Select an option

  • Save mn-48/d6cf47c914e1818f1cf5886ddff97c51 to your computer and use it in GitHub Desktop.

Select an option

Save mn-48/d6cf47c914e1818f1cf5886ddff97c51 to your computer and use it in GitHub Desktop.

Server_load_test1.py

import requests
import time

# API URL
url = "http://103.164.92.62:8000/graphql/"

# GraphQL mutation for authentication
mutation = """
mutation {
  tokenAuth(username: "1111250", password: "p1234") {
    success
    errors
    token
    refreshToken
    user {
      id
      username
      firstName
      lastName
    }
  }
}
"""

# Request Headers
headers = {
    "Content-Type": "application/json"
}

# Number of test requests
num_requests = 100
response_times = []

# Measure request and response times
for _ in range(num_requests):
    start_time = time.time()
    response = requests.post(url, json={"query": mutation}, headers=headers)
    end_time = time.time()

    response_time = end_time - start_time
    response_times.append(response_time)

# Calculate average response time
avg_response_time = sum(response_times) / num_requests

print(f"Average Response Time: {avg_response_time:.4f} seconds")

server_load_test2.py

import requests
import time

# API details
url = "http://103.164.92.62:8000/graphql/"
headers = {
    "Authorization": "JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6IjExMTg1MjYiLCJleHAiOjE3MzU1NTUxMjMsIm9yaWdJYXQiOjE3MzU1NTQ4MjN9.q9n0_7B8-II9tNIgZIBE2cjCmY7sK0MFm8S2lvW10GY",
    "Content-Type": "application/json"
}
query = """
{
  myChatRoomMessages(chatRoomId: "Q2hhdFJvb21Ob2RlOjI3OQ==", first: 10) {
    edges {
      node {
        id
        messageType
        text
        image
      }
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}
"""

# Number of requests to send
num_requests = 100
response_times = []

# Measure request/response times
for _ in range(num_requests):
    start_time = time.time()
    response = requests.post(url, json={"query": query}, headers=headers)
    end_time = time.time()
    
    response_time = end_time - start_time
    response_times.append(response_time)

# Calculate average response time
avg_response_time = sum(response_times) / num_requests
print(f"Average Response Time: {avg_response_time:.4f} seconds")


Step0: To get user JWT token (Test User)

url: http://103.164.92.62:8000/graphql/


mutation{
  tokenAuth(username:"1111250", password:"p1234"){
    success
    errors
    token
    refreshToken
    user{
        id
        username
        firstName
        lastName

      }
    }
  }

Step1: Run this

url: http://103.164.92.62:8000/graphql/

subscription {
    onNewMessage(chatroomId: "Q2hhdFJvb21Ob2RlOjE2") {
      message {
        id
        messageType
        text

        sender {
          id
          username

        }
      }
    }
  }

Step2: Send Message Post request (JWT token required)

url: http://103.164.92.62:8000/graphql/

token: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6IjExMTg1MjYiLCJleHAiOjE3MzU1NTUxMjMsIm9yaWdJYXQiOjE3MzU1NTQ4MjN9.q9n0_7B8-II9tNIgZIBE2cjCmY7sK0MFm8S2lvW10GY

mutation {
  sendMessage(input: {chatRoomId: "Q2hhdFJvb21Ob2RlOjE2", messageType: "text", text: "Enter your text is here as you wish"}) {
    message {
      id
    }
  }
}

Step 2 and Step 3 use different Browser

Step3: Get All Message (JWT token required)

url: http://103.164.92.62:8000/graphql/ token: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6IjExMTg1MjYiLCJleHAiOjE3MzU1NTUxMjMsIm9yaWdJYXQiOjE3MzU1NTQ4MjN9.q9n0_7B8-II9tNIgZIBE2cjCmY7sK0MFm8S2lvW10GY


query {
  myChatRoomMessages(chatRoomId: "Q2hhdFJvb21Ob2RlOjI3OQ==", first: 10) {
    edges {
      node {
        id
        messageType
        text
        image

      }
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}

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