ydf0509 / tps_threadpool_executor

pip install tps_threadpool_executor , tps_threadpool_executor,function run times every second Frequency control , multi thread + proccess
3 stars 0 forks source link

无法突破限制 #1

Open FynnFbc opened 1 year ago

FynnFbc commented 1 year ago

TpsThreadpoolExecutorWithMultiProcess 多进程无法满负载运行,最多5进程为最大效率,设置10进程效率同5进程一样 如何改进 内网做web压测

ydf0509 commented 1 year ago

建议用funboost框架做压测,这个多进程加多线程,是用的multiprocess Queue性能不好,建议直接funboost框架,开启多进程叠加多线程,无论多少cpu是多少核心都能吧cpu耗光。建议上funboost,这个模块的multiprocess Queue性能不好

FynnFbc commented 1 year ago

多谢,没想到还有这么厉害的框架

ydf0509 commented 1 year ago
# -*- coding: utf-8 -*-
# @Author  : ydf
# @Time    : 2022/8/8 0008 14:57
import sys
import time

from funboost import boost, BrokerEnum
from nb_http_client import HttpOperator, ObjectPool

http_pool = ObjectPool(object_type=HttpOperator, object_pool_size=100, object_init_kwargs=dict(host='www.baidu.com', port=80),
                       max_idle_seconds=30)

@boost('test_baidu', broker_kind=BrokerEnum.REDIS, log_level=20, is_print_detail_exception=False, concurrent_num=200,qps=1000,
       is_using_distributed_frequency_control=True)
def request_url(urlx,n):
    with http_pool.get() as conn:
        r1 = conn.request_and_getresponse('GET', urlx)
        sys.stdout.write(f'{n} {r1.text[:10]} {r1.status} {time.strftime("%H:%M:%S")} \n')

if __name__ == '__main__':
    request_url.clear()
    for i in range(10000):
        url = 'https://www.baidu.com/content-search.xml'
        # url = 'http://mini.eastday.com/assets/v1/js/search_word.js'
        request_url.push(url,i)

    request_url.multi_process_consume(2)

你看控制台的第一个打印请求时间和最后一个请求时间,就知道了,我发布10000个url,设置qps为1000,精确10秒搞定了。设置qps为2000,只需要5秒完成,你可以加大 multi_process_consume的进程数量,结合nb_http_client,即使压测机器只有4核心,只要网速和服务端没瓶颈,funboost每秒请求完成10000次响应很容易

ydf0509 commented 1 year ago

需要用我写的nb_http_client,或者 urllib3,不要用requests,只要压测机器自身没网速 cpu瓶颈,每秒破万很容易。

ydf0509 commented 1 year ago

需要用我写的nb_http_client,或者 urllib3,不要用requests,只要压测机器自身没网速 cpu瓶颈,每秒破万很容易。

如果你是压测内网 的api,不走公网带宽,api接口流量内容小,压测机器有16核心,funboost每秒可以压测10万次。

FynnFbc commented 1 year ago

我python3.11无法安装,window和Linux都不行 image

ydf0509 commented 1 year ago

支持到python3.9

ydf0509 commented 1 year ago

funboost 18.3版本 更新依赖包eventlet gevent,现在支持3.11版本了。

FynnFbc commented 1 year ago

好的,感谢大佬

FynnFbc commented 1 year ago

windows报错 image Linux报错 image

ydf0509 commented 1 year ago

windows报错 image Linux报错 image

18.3版本安装gevent eventlet都是正常的。你安装的老版本

ydf0509 commented 1 year ago

pip install funboost==18.3 ,我是测试了才会发的,

老版本不支持3.10以上,是之前的三方包eventlet gevent不支持3.10以上造成的

FynnFbc commented 1 year ago

明白了,是我用的国内更新源没有同步到最新的版本,我用官方源安装才有18.3版本

ydf0509 commented 1 year ago

""" 官方 https://pypi.org/simple 清华 https://pypi.tuna.tsinghua.edu.cn/simple 豆瓣 https://pypi.douban.com/simple/ 阿里云 https://mirrors.aliyun.com/pypi/simple/ 腾讯云 http://mirrors.tencentyun.com/pypi/simple/

打包上传 python setup.py sdist upload -r pypi

python setup.py bdist_wheel

python setup.py bdist_wheel ; python -m twine upload dist/funboost-15.0-py3-none-any.whl python setup.py bdist_wheel && python -m twine upload dist/funboost-18.3-py3-none-any.whl python setup.py sdist & twine upload dist/funboost-10.9.tar.gz

最快的下载方式,上传立即可安装。阿里云源同步官网pypi间隔要等很久。 ./pip install funboost==3.5 -i https://pypi.org/simple
最新版下载 ./pip install funboost --upgrade -i https://pypi.org/simple
"""

FynnFbc commented 1 year ago

好的,感谢感谢

FynnFbc commented 1 year ago

image 这个写法没问题吧,咋qps这么低 image

ydf0509 commented 1 year ago

太low你,你使用的是sqlite作为消息队列肯定不能快了,10进程1000次每秒算快了。而且sqlite不是多进程安全的,自己去看funboost的broker_kind作用吧,你这写的使用sqlite作为消息队列,频繁锁文件,真的很low。

要你这么说sqlite性能暴击mysql orcal了吗。

ydf0509 commented 1 year ago

而且一直在函数里面实例化httpconection,为什么不用连接池呢。

ydf0509 commented 1 year ago

默认不修改配置文件或者传递broker_kind是使用sqlite作为消息队列,是为了不需要安装消息队列,建议安装个rabbitmq,或者最少是安装个redis。

FynnFbc commented 1 year ago

好的