Discover python performance profiling, include the articles, news, trends, analysis and practical advice about python performance profiling on alibabacloud.com
The Python standard library provides three modules for analyzing program performance, Cprofile, profile and hotshot, plus an auxiliary module stats. These modules provide deterministic analysis of Python programs, as well as a report generation tool that allows users to quickly check and analyze resultsCProfile: Based on the Lsprof C language implementation of th
Python is not well-known for performance, but mastering some skills can also maximize program performance and avoid unnecessary waste of resources.1. Using Local variablesTry to use local variables instead of global variables: Ease of maintenance, improved performance, and memory savings.Use local variables to replace
Python Flask Fast Build high-performance large web site project combat video": HTTPS://PAN.BAIDU.COM/S/1CUGGNBUVPTYZ5VVWBHSDRG"Flask is unique as a micro-framework for the most popular Python web development. It does not force developers to follow a pre-built development specification, providing developers with freedom and creative space. Suddenly found this is v
selenium related articles. three solution ideasafter the analysis of HTML source code, you can find that each indicator data corresponds to an HTML file stored in the report directory , as long as the use of python html The parsing technique gets, and then modifies the data slightly, adding a number of HTML-formatted strings in the form of a label , and finally writing to the. html file. four Python HTML
= thread.allocate_lock() lock.acquire() locks.append(lock) for i in nloops: thread.start_new_thread(loop0,(i,loops[i],locks[i])) sleep(1) for i in nloops: while locks[i].locked():pass print ‘all DONE at:‘,ctime()if __name__ == ‘__main__‘: main()Output Result:/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /data/study/python/project/test/onethr.pystarting at: Mon Mar 26 13:32:09 201
", "password": "" }) @task def index(self): self.client.get("/") @task def about(self): self.client.get("/about/")class WebsiteUser(HttpLocust): task_set = WebsiteTasks min_wait = 5000 max_wait = 15000Other informationPython Module Introduction-locustio: Performance testing tools Locustio Chinese documentsBackgroundWe have studied existing solutions that are not in line with the requirements. Like A
A description of the application scenarioDuring the performance testing of Nginx,redis, I wanted to draw the collected data, but Excel is not proficient and there are no familiar drawing tools. Anyway, it's all about learning, not trying to draw with Python, and then practicing Python.Two Python drawing tool learningResources:Http://pbpython.com/visualization-too
Introduction
With the Psutil module (https://pypi.python.org/pypi/psutil/), it is very convenient to monitor the system's CPU, memory, disk IO, network bandwidth and other performance parameters, whether the following code to monitor the CPU resource consumption of a particular program, Prints the monitoring data, the final drawing is displayed, and is saved as a backup of the specified PDF document.
Demo Code
#!/usr/bin/env
From locust import TaskSet, task, HttplocustImport queueClass Userbehavior (TaskSet):@taskdef test_register (self):Try# get_nowait () does not take data directly crashes; get () No data will waitdata = Self.locust.user_data_queue.get_nowait () # Value order ' username ': ' test0000 ', ' username ': ' test0001 ', ' username ': ' Test0002 ' ...Except queue. Empty: # When the data is not taken, go herePrint (' account data run out, test ended. ')Exit (0)Print (' Register with User: {}, pwd: {} '. F
from locust Import TaskSet, task, Httplocust Class Userbehavior (TaskSet): def on_start (self): # when modulo When the user starts executing the Taskset class, the On_Start method is called Self.index = 0 @task def test_visit (self): URL = self.locust.share_data[ Self.index] # takes self.locust.share_data Self.index = (self.index + 1)% len ( self.locust.share_data) # Self.index value less than SE Lf.locust.share_data the length of the loop, generate r = self.client.get (URL) # Taskset
and write Information #psutil.disk_io_counters (perdisk=true) # ' perdisk=true ' parameter to get a single partition IO number, read and write informationNetwork information:The network information mainly includes the following parts:
Bytes_sent (number of bytes sent)
Bytes_recv (number of bytes received)
Packets_sent (number of packets sent)
PACKETS_RECV (number of packets received)
Psutil.net_io_counters () How to use:#import psutil#psutil.net_io_counters () # Get ne
Use Python Tornado framework and memcached page to improve blog performance. tornadomemcached
Cause
Blog is a set of systems that are not updated frequently, but every time you refresh the page, updating the database is a waste of resources. Adding static page generation is a solution, caching is also a better idea. You can use Memcached to add a small amount of code for caching, and avoid generating static
. Monitor the time-consuming of suspicious methodsFor ease of monitoring, two additional adorners are added to count time-consumingdefcosts (FN):def_wrapper (*args, * *Kwargs): Start=time.time () FN (*args, * *Kwargs)Print "%s function cost%s seconds"% (FN.__name__, Time.time ()-start)return_wrapperdefCosts_with_info (info):def_wrapper (FN):Print "Info:"+Inforeturncosts (FN)return_wrapperWhen the method needs to be monitored, add @costs or @costs_with_info ("some infomation") @costs def C
, this atom small machine is much more fierce than the IBM server. The hardware is growing fast.
With hardware and software environment:
Atom D525 1.6G Dual core, 2gram,freebsd 9,nginx 1.2.2,python 2.7.3, other IBM servers.
And on this atom machine, the-w parameter has a significant contribution to RPS ... It seems that the problem with the old server is not obvious, but is not sure whether it is a hardware problem or OS problem. Conclusions
Meinheld
Original: Https://docs.quantifiedcode.com/python-anti-patterns/performance/using_key_in_list_to_check_if_key_is_ Contained_in_a_list.htmlUsing the key in list to iterate the list will potentially cost n iterations to complete, and N is the key in the list position. If allowed, the list can be converted to set or dict, because Python finds elements in set or dict
drawdown(spy)1 loops, best of 3: 1.21 s per loop
HMM 1.2 seconds is not the too speedy for such a simple function. There is some things this could be a great drag to performance, such as a list *highwatermark* so is being Appende D on each loop iteration. Accessing Series by their index should also involve some processing the is isn't strictly necesarry. Let's take a look at what happens when the This function was rewritten to work with NumPy
The bsddb module is used to operate bdb. bdb is a famous Berkeley dB with excellent performance. MySQL's storage backend engine supports bdb. Here is a brief introduction to the use of bsddb.
Different from relational databases, bdb stores only one pair of data consisting of key and value. It is used just like a python dictionary and cannot directly represent multiple fields, when you want to store data wi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.