Profile django

Post on 13-Jan-2017

659 views 0 download

Transcript of Profile django

Profiling Django

1. models = MyModel.object.all()

2. filtered = models.filter( size__lte=20 )

3. fronts = filtered[:9]

4. print(fronts[0].attribute)

• QuerySet lazy evaluation

• https://docs.djangoproject.com/es/1.9/ref/models/querysets/

• profile

Profile

• Profile

view

• django-debug-toolbar

• django-debug-toolbar-line-profiler

Performance

silk

• view benchmark

• Query

Demo

Django Command

cProfile

python -m cProfile -o my-profile-data.out manage.py

cprofilev -f my-profile-data.out -a 0.0.0.0 -p 4000

• function.

line profiler

kernprof -l manage.py <Command>

python -m line_profiler manage.py.lprof

• db

• django orm orz…

code snippet def store_conversion(post_back, conversion_type): time_stamp = dateutil.parser.parse(post_back['at'])

nested_data = post_back['data'] if not nested_data: return

try: ConversionRecord.objects.create( time_stamp=time_stamp ) except IntegrityError: pass

Profile

• Python Parse

60

for index in range(1, piece+1): r = update_metric_task(index, total_count, piece, metrics_qs, records) jobs.append(r)

Query task

benchmark

• query set…

Reason

Pickling QuerySets¶

If you pickle a QuerySet,

this will force all the results to be loaded into memory prior to pickling.

• Query Set Task

• Task QuerySet

• bulk create

• call save method

• Unittest Sqlite Process

• TEST_NAME, Sqlite lock

• postgres sql

• Profile

• Django ORM