Home Backend Development Python Tutorial Sample code for concurrency testing after flask deployment in Python

Sample code for concurrency testing after flask deployment in Python

Jul 24, 2017 pm 02:08 PM
flask test deploy

After deployment, check the concurrency supported by flask. Let’s take a look at 300 concurrency. Up the code

import threading, time, requests
url = ""total = 0
suc = 0
fail = 0
exception = 0
maxtime=0
mintime=100gt3=0
lt3=0class RequestThread(threading.Thread):def __init__(self, thread_name):  
        threading.Thread.__init__(self)  
        self.test_count = 0def run(self):
        self.test_performace()def test_performace(self):  global totalglobal sucglobal failglobal exceptionglobal gt3global lt3try:  
                st = time.time()  
                conn = requests.get(url)
                res = conn.status_codeif res== 200:
                    total+=1suc+=1else:
                    total+=1fail+=1time_span = time.time()-st  print ('%s:%f\n'%(self.name,time_span)  )
                self.maxtime(time_span)  
                self.mintime(time_span)  if time_span>3:
                    gt3+=1else:
                    lt3+=1except Exception as e:  print (e  )
                total+=1exception+=1def maxtime(self,ts):  global maxtimeprint (ts)if ts>maxtime:
                maxtime=tsdef mintime(self,ts):  global mintimeif ts<mintime:
                mintime=tsprint (&#39;===========请求开始===========&#39;  )
start_time = time.time()
thread_count = 100i = 0  
while i <= thread_count:  
    t = RequestThread("线程:" + str(i))
    t.start()  
    i += 1  t=0while total<thread_count|t>20:print ("总数:%d,成功数:%d,失败:%d,异常:%d\n"%(total,suc,fail,exception)  )print (url)
        t+=1time.sleep(1)print (&#39;===========task end===========&#39;)print ("总数:%d,成功:%d,失败:%d,异常:%d"%(total,suc,fail,exception))print (&#39;响应最大时间:&#39;,maxtime)print (&#39;响应最小时间&#39;,mintime)print (&#39;大于3秒的响应:%d,占比:%0.2f&#39;%(gt3,float(gt3)/total))print (&#39;小于3秒:%d,占比:%0.2f&#39;%(lt3,float(lt3)/total))
Copy after login

Look at Baidu request response

What about mine?

It’s pretty good. It supports concurrency, but it’s not very accurate. You can refer to it. You can also use this for interfaces

The above is the detailed content of Sample code for concurrency testing after flask deployment in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What do you think of furmark? - How is furmark considered qualified? What do you think of furmark? - How is furmark considered qualified? Mar 19, 2024 am 09:25 AM

What do you think of furmark? 1. Set the &quot;Run Mode&quot; and &quot;Display Mode&quot; in the main interface, and also adjust the &quot;Test Mode&quot; and click the &quot;Start&quot; button. 2. After waiting for a while, you will see the test results, including various parameters of the graphics card. How is furmark qualified? 1. Use a furmark baking machine and check the results for about half an hour. It basically hovers around 85 degrees, with a peak value of 87 degrees and room temperature of 19 degrees. Large chassis, 5 chassis fan ports, two on the front, two on the top, and one on the rear, but only one fan is installed. All accessories are not overclocked. 2. Under normal circumstances, the normal temperature of the graphics card should be between &quot;30-85℃&quot;. 3. Even in summer when the ambient temperature is too high, the normal temperature is &quot;50-85℃

Start from scratch and guide you step by step to install Flask and quickly establish a personal blog Start from scratch and guide you step by step to install Flask and quickly establish a personal blog Feb 19, 2024 pm 04:01 PM

Starting from scratch, I will teach you step by step how to install Flask and quickly build a personal blog. As a person who likes writing, it is very important to have a personal blog. As a lightweight Python Web framework, Flask can help us quickly build a simple and fully functional personal blog. In this article, I will start from scratch and teach you step by step how to install Flask and quickly build a personal blog. Step 1: Install Python and pip Before starting, we need to install Python and pi first

Guide to installing the Flask framework: Detailed steps to help you install Flask correctly Guide to installing the Flask framework: Detailed steps to help you install Flask correctly Feb 18, 2024 pm 10:51 PM

Flask framework installation tutorial: Teach you step by step how to correctly install the Flask framework. Specific code examples are required. Introduction: Flask is a simple and flexible Python Web development framework. It's easy to learn, easy to use, and packed with powerful features. This article will lead you step by step to correctly install the Flask framework and provide detailed code examples for reference. Step 1: Install Python Before installing the Flask framework, you first need to make sure that Python is installed on your computer. You can start from P

Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Apr 22, 2024 pm 12:50 PM

The "Inaction Test" of the new fantasy fairy MMORPG "Zhu Xian 2" will be launched on April 23. What kind of new fairy adventure story will happen in Zhu Xian Continent thousands of years after the original work? The Six Realm Immortal World, a full-time immortal academy, a free immortal life, and all kinds of fun in the immortal world are waiting for the immortal friends to explore in person! The "Wuwei Test" pre-download is now open. Fairy friends can go to the official website to download. You cannot log in to the game server before the server is launched. The activation code can be used after the pre-download and installation is completed. "Zhu Xian 2" "Inaction Test" opening hours: April 23 10:00 - May 6 23:59 The new fairy adventure chapter of the orthodox sequel to Zhu Xian "Zhu Xian 2" is based on the "Zhu Xian" novel as a blueprint. Based on the world view of the original work, the game background is set

Yolov10: Detailed explanation, deployment and application all in one place! Yolov10: Detailed explanation, deployment and application all in one place! Jun 07, 2024 pm 12:05 PM

1. Introduction Over the past few years, YOLOs have become the dominant paradigm in the field of real-time object detection due to its effective balance between computational cost and detection performance. Researchers have explored YOLO's architectural design, optimization goals, data expansion strategies, etc., and have made significant progress. At the same time, relying on non-maximum suppression (NMS) for post-processing hinders end-to-end deployment of YOLO and adversely affects inference latency. In YOLOs, the design of various components lacks comprehensive and thorough inspection, resulting in significant computational redundancy and limiting the capabilities of the model. It offers suboptimal efficiency, and relatively large potential for performance improvement. In this work, the goal is to further improve the performance efficiency boundary of YOLO from both post-processing and model architecture. to this end

What are the differences between function testing and coverage in different languages? What are the differences between function testing and coverage in different languages? Apr 27, 2024 am 11:30 AM

Functional testing verifies function functionality through black-box and white-box testing, while code coverage measures the portion of code covered by test cases. Different languages ​​(such as Python and Java) have different testing frameworks, coverage tools and features. Practical cases show how to use Python's Unittest and Coverage and Java's JUnit and JaCoCo for function testing and coverage evaluation.

Flask installation and configuration tutorial: a tool to easily build Python web applications Flask installation and configuration tutorial: a tool to easily build Python web applications Feb 20, 2024 pm 11:12 PM

Flask installation and configuration tutorial: A tool to easily build Python Web applications, specific code examples are required. Introduction: With the increasing popularity of Python, Web development has become one of the necessary skills for Python programmers. To carry out web development in Python, we need to choose a suitable web framework. Among the many Python Web frameworks, Flask is a simple, easy-to-use and flexible framework that is favored by developers. This article will introduce the installation of Flask framework,

The new king of domestic FPS! 'Operation Delta' Battlefield Exceeds Expectations The new king of domestic FPS! 'Operation Delta' Battlefield Exceeds Expectations Mar 07, 2024 am 09:37 AM

"Operation Delta" will launch a large-scale PC test called "Codename: ZERO" today (March 7). Last weekend, this game held an offline flash mob experience event in Shanghai, and 17173 was also fortunate to be invited to participate. This test is only more than four months away from the last time, which makes us curious, what new highlights and surprises will "Operation Delta" bring in such a short period of time? More than four months ago, I experienced "Operation Delta" in an offline tasting session and the first beta version. At that time, the game only opened the "Dangerous Action" mode. However, Operation Delta was already impressive for its time. In the context of major manufacturers flocking to the mobile game market, such an FPS that is comparable to international standards

See all articles