【问题标题】:Locust Error nodename nor servname provided, or not known提供 Locust 错误节点名或服务名,或未知
【发布时间】:2020-08-21 07:06:15
【问题描述】:

第一次来电长听:)

我正在一个站点上运行 locust 测试(或至少尝试过),但 100% 失败并出现以下错误

1

from locust import HttpLocust,TaskSet,task,之间 从 locust.events 导入 request_success 导入日志、上下文库、请求 尝试: 从 http.client 导入 HTTPConnection # py3 导入错误除外: 从 httplib 导入 HTTPConnection # py2

def debug_requests_on(): '''开启请求模块的日志记录。''' HTTPConnection.debuglevel = 1

    logging.basicConfig()
    logging.getLogger().setLevel(logging.DEBUG)
    requests_log = logging.getLogger("requests.packages.urllib3")
    requests_log.setLevel(logging.DEBUG)
    requests_log.propagate = True

def call_hook(resp, *args, **kwargs): print(f"{resp.url}返回{resp.status_code}的状态码")

类 RedirectTaskSet(TaskSet):

def on_start(self):
    pass

def on_stop(self):
    pass

@task
def redirect_task(self):
    name = '/voting'
    response =  self.client.get('/voting', allow_redirects=True, name=name)
    print("Response status code:", response.status_code)
    print("Response history:", response.history)

    if not response.ok:
        self.log_failure('Request failed ', name, response)

def log_failure(self, message, name, response):
    pass # add some logging

#@task
#def log_response_codes(self):
#    requests.get('https://thevoice.com.au/voting', hooks={'response': call_hook})

类 RedirectLocust(HttpLocust):

task_set = RedirectTaskSet
wait_time = between(0.5,3)
host = "https://www.thevoice.com.au"
#debug_requests_on()

【问题讨论】:

  • 嗨!您需要提供更多详细信息(例如您的负载测试脚本),以便有人能够帮助您。该错误通常意味着找不到您指定的 url 中的主机名(www.thevoice.com.au 不存在)
  • 感谢您回复cyberwiz :) 我已将 locustfile.py 添加到我的问题中。网站加载它是一个重定向,我们要加载测试重定向。

标签: python locust


【解决方案1】:

感谢您添加测试计划。问题是 thevoice.com.au 无法解析(没有 DNS 条目)。它与蝗虫无关。您可以尝试使用 curl、ping 或任何其他工具进行确认。

~ curl https://www.thevoice.com.au
curl: (6) Could not resolve host: www.thevoice.com.au

【讨论】:

  • 所以我发现如果我将用户负载保持在 200 以下就可以了,但是一旦我达到 300 以上,它就会给我这个错误,我的限制打开文件限制设置为 5000。想知道是否它可能与公司的 AV 有关(不能禁用) Ps 非常感谢您对此进行调查
  • 如果您遇到某种 DNS 限制,您可以尝试将 dns 名称替换为 IP 地址(如 1.2.3.4)。
  • 其实我刚才遇到了同样的错误(增加负载时)。你在 MacOS 上运行吗?您是否尝试过切换到 FastHttpUser?您能否编辑您的问题以关注此问题(增加的负载)
  • 找到了一个解决方案,基本上将以下行添加到我的 Locustfile.py resource.setrlimit(resource.RLIMIT_NOFILE, (20000, 21000))
猜你喜欢
  • 2017-04-18
  • 1970-01-01
  • 1970-01-01
  • 2011-05-07
  • 1970-01-01
  • 2012-11-02
  • 1970-01-01
  • 1970-01-01
  • 2015-03-26
相关资源
最近更新 更多