项目作者: FesonX

项目描述 :
Python Flask-SQLAlchemy Memory Leaks Test - Python Flask-SQLAlchemy 内存泄漏测试
高级语言: Python
项目地址: git://github.com/FesonX/memoryTest.git
创建时间: 2020-02-10T14:33:44Z
项目社区:https://github.com/FesonX/memoryTest

开源协议:MIT License

下载


MemoryTest

Install Guide

Environment

  1. Install interpreter, develop under Python 3.6
  2. Install Python packagepip install -r requirements.txt
  3. Install MySQL

Database Prepare

  1. create your own db, create instance folder under project root path
  2. create config.py under instance folder, add SQLALCHEMY_DATABASE_URI
  3. run src/models.py to create table

Run Memory Leaking Test

  1. python item_recorder.py

If you want to show the memory changes of a method

  1. Install package. pip install memory_profile
  2. Add a decorator on function
    ```python
    import profile

@profile
def method_to_log():
pass

  1. ### If you need to generate memory figure
  2. 1. install package. `pip install matplotlib`
  3. 2. record memory changes. `mprof run item_recorder.py`
  4. 3. display image. `mprof plot mprofile_xxx.dat`, `xxx` like a timestamp auto generated
  5. ### If you need to record object growth
  6. The `objgraph.growth` will show the increase in peak object counts since last call.
  7. Default is Top 10.
  8. 1. install package. `pip install objgraph`
  9. 2. add code
  10. ```python
  11. import objgraph
  12. ...# some code above...
  13. objgraph.show_growth()
  14. # If the program like a event-loop
  15. # Try to catch `KeyboardInterrupt` event, like:
  16. try:
  17. pass
  18. except KeyboardInterrupt as e:
  19. objgraph.show_growth()

To fix the memory leak

Uncomment the line in src/__init__.py, or disable debug mode.

  1. # app.config.update(SQLALCHEMY_RECORD_QUERIES=False)