Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Performances Django REST framework - DjangoCong...
Search
Ordoquy Xavier - Linovia
June 16, 2016
Programming
130
0
Share
Performances Django REST framework - DjangoCong 2016
Un petit coup d'oeil sur les performances de Django REST framework.
Ordoquy Xavier - Linovia
June 16, 2016
More Decks by Ordoquy Xavier - Linovia
See All by Ordoquy Xavier - Linovia
SQLAlchemy - un ami qui vous veut du bien
xordoquy
0
18
pycon.fr 2018 - Django REST framework workshop
xordoquy
0
350
mauvaises bonnes idées pour REST
xordoquy
1
400
Authentication and Permissions with Django REST framework
xordoquy
0
190
Buildbot 0.9
xordoquy
0
110
Présentation de l'architecture REST - meetup Django Paris
xordoquy
0
110
Django REST framework workshop @Djangocon Europe 2015
xordoquy
0
130
Django REST framework - DjangoConG 2015
xordoquy
3
150
Django REST framework workshop - DjangoCong 2015
xordoquy
1
130
Other Decks in Programming
See All in Programming
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
330
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.2k
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
340
初めてのRubyKaigiはこう見えた
jellyfish700
0
390
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
760
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
430
TSKaigi 2026 TypeScriptバックエンドのオブザーバビリティ戦略 — Datadog × NestJSの実践
taiseiyamamotoan
1
210
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
690
net-httpのHTTP/2対応について
naruse
0
400
ECR拡張スキャンでSBOMを収集して サプライチェーン攻撃の影響調査を 爆速で終わらせてみた
akihisaikeda
2
210
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
420
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
160
Evolving SEO for Evolving Search Engines
ryanjones
0
210
Automating Front-end Workflow
addyosmani
1370
210k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
GitHub's CSS Performance
jonrohan
1033
470k
My Coaching Mixtape
mlcsv
0
140
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
200
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
44k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
210
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Transcript
Django REST framework performances DjangoCong 2016 Xavier Ordoquy (@linovia_net)
Extensibilité =/= Performance
Extensible: Plus de requêtes par seconde
Performance: Moins de temps par requête
Extensible: Architecture
Performance: Algorithme
La mesure de performance: subjectif
Python 3.4 Python 3.5 16,711 ms 22,322 ms
Django vs. Django REST framework
• Négociation de contenu • Passeurs • Renderers • Throttling
• Pagination • Authentification • Permissions
class Invoice(models.Model): name = models.CharField(max_length=128) comments = models.TextField() total =
models.DecimalField( max_digits=9, decimal_places=2) owner = models.ForeignKey( settings.AUTH_USER_MODEL) assignee = models.ForeignKey( settings.AUTH_USER_MODEL)
@csrf_exempt def create_invoice(request): if request.method == 'GET': serialized_invoices = [
serialize(invoice) for invoice in models.Invoice.objects.all() ] return HttpResponse( content=json.dumps(serialzied_invoices), content_type='application/json', )
@csrf_exempt def create_invoice(request): if request.method == 'POST': form = forms.Invoice(request.POST
or None) if form.is_valid(): invoice = form.save() result = serialize(invoice) return HttpResponse( content=json.dumps(result), content_type='application/json', )
class InvoiceSerializer(serializers.ModelSerializer): class Meta: model = models.Invoice fields = ('id',
'name', 'comments', 'total') class InvoiceViewSet(viewsets.ModelViewSet): queryset = models.Invoice.objects.all() serializer_class = serializers.Invoice def perform_create(self, serializer): serializer.save(owner_id=1, assignee_id=1)
0 0,9 1,8 2,7 3,6 3,473 ms 2,159 ms Django
DRF Liste avec 2 objets +60%
0 3,25 6,5 9,75 13 12,717 ms 9,599 ms Django
DRF Liste avec 100 objets +32%
0 3,25 6,5 9,75 13 10,578 ms 12,868 ms Django
DRF Creation d’un objet -21%
Qui fait quoi et quand ?
ORM
Cycle de la requête
Sérialisation
Vue
Titre 0,20 0,40 0,60 0,80 1,00 1,20 11,36 % 13,7
% 7,9 % 67,0 % ORM Sérialiseur Vue Requête Détail d’un objet
0,00 % 20,00 % 40,00 % 60,00 % 80,00 %
100,00 % 120,00 % 6,271 % 1,621 % 55,349 % 36,759 % ORM Sérialiseur Vue Requête Liste de 100 objets
0,00 % ms 20,00 % ms 40,00 % ms 60,00
% ms 80,00 % ms 00,00 % ms 20,00 % ms 5,808 % 2,538 % 7,874 % 83,78 % ORM Sérialiseur Vue Requête Création d’un objet
Optimiser
Cacher les requêtes DB
Supprimer la sérialisation
def list(self, request, *args, **kwargs): queryset = self.filter_queryset( self.get_queryset()) #
Pagination serializer = self.get_serializer( queryset, many=True ) return Response(serializer.data)
def list(self, request, *args, **kwargs): queryset = self.filter_queryset( self.get_queryset()) #
Pagination data = models.Invoice.objects.values( 'id', 'name', 'comments', 'total' ) return Response(data)
• Nettoyer les middlewares • Faire un rendu direct •
Désactiver la négociation de contenu
Moments WTF ?!?
queryset évalué 2 fois
class RelatedField(Field): def get_queryset(self): queryset = self.queryset if isinstance(queryset, (QuerySet,
Manager)): queryset = queryset.all() return queryset
WTF ? selected_related n’est pas fonctionnel ?
selected_related n’est pas fonctionnel durant l’update ! (Django #21584)
Stop aux ModelSerializers !
Vive les Serializers !
Questions ? https://www.dabapps.com/blog/api-performance-profiling- django-rest-framework/ https://github.com/xordoquy/django-rest-framework- benchmark