如何使用Locust对Apollo服务器进行负载测试?

4

有人知道如何对Apollo服务器进行负载测试吗?

 class UserBehavior(TaskSet):
        def on_start(self):
            self.login()

        @task
        def login(self):
            headers = {"content-type": "application/json"}
            self.client.post("/", data=json.dumps({
            "query": "mutation { login(username:\"9849999983\", password: \"123456\") {  token User { id fullName "
                     "email phoneNumber } } } "
            },
                headers=headers))


    class ApolloSample(HttpLocust):
        host = "https://sampleurl.com/api"
        min_wait = 20000
        max_wait = 50000
        task_set = UserBehavior

这个问题在于,self.client.post("/") 方法没有特定的终点。由于Graphql基本上由查询和变更组成。
2个回答

4
以下内容可用于GraphQL查询和变异。不要错过接受标头(Accept headers)查询

response = self.client.post(
            "http://localhost:5424/graphql",
            name="GraphQL",
            headers={
                "Accept": "application/graphql",
                "Authorization": "<Authorization-Token>"
            },
            json={"query": "<Your-GraphQL-Query>" }
        )

变异

response = self.client.post(
            "http://localhost:5424/graphql",
            name="GraphQL",
            headers={
                "Accept": "application/graphql",
                "Authorization": "<Authorization-Token>"
            },
            json={"query": "<Your-GraphQL-Query>,"
                  "operationName": "<Operation-Name>,
                  "variables":"<Input-Variables>" }
        )


0

response = self.client.post(
            "http://localhost:5424/graphql",
            name="GraphQL",
            headers={
                "Accept": "application/graphql",
                "Authorization": "<Authorization-Token>"
            },
            json={"query": "<Your-GraphQL-Query>" }
        )


1
目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何撰写好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接