Profile django

33
Profiling Django

Transcript of Profile django

Page 1: Profile django

Profiling Django

Page 2: Profile django

1. models = MyModel.object.all()

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

3. fronts = filtered[:9]

4. print(fronts[0].attribute)

Page 3: Profile django

• QuerySet lazy evaluation

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

Page 4: Profile django

• profile

Page 5: Profile django

Profile

• Profile

Page 6: Profile django

view

• django-debug-toolbar

• django-debug-toolbar-line-profiler

Page 7: Profile django
Page 8: Profile django
Page 9: Profile django

Performance

Page 10: Profile django

silk

• view benchmark

• Query

Page 11: Profile django
Page 12: Profile django
Page 13: Profile django

Demo

Page 14: Profile django

Django Command

Page 15: Profile django

cProfile

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

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

Page 16: Profile django
Page 17: Profile django

• function.

Page 18: Profile django

line profiler

Page 19: Profile django

kernprof -l manage.py <Command>

python -m line_profiler manage.py.lprof

Page 20: Profile django
Page 21: Profile django

• db

• django orm orz…

Page 22: Profile django

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

Page 23: Profile django

Profile

• Python Parse

Page 24: Profile django
Page 25: Profile django

60

Page 26: Profile django

Page 27: Profile django

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

Query task

Page 28: Profile django

benchmark

• query set…

Page 29: Profile django

Reason

Pickling QuerySets¶

If you pickle a QuerySet,

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

Page 30: Profile django

• Query Set Task

• Task QuerySet

Page 31: Profile django

• bulk create

• call save method

Page 32: Profile django

• Unittest Sqlite Process

• TEST_NAME, Sqlite lock

• postgres sql

Page 33: Profile django

• Profile

• Django ORM