SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
Arnaud Bouchez - Synopse
Frameworks
Tuning
Arnaud Bouchez
• Open Source Founder
mORMot 2
SynPDF, dmustache
• Modern Delphi and FPC
DDD, SOA, ORM, MVC
Performance, SOLID
• Synopse
https://synopse.info
Arnaud Bouchez
dev @ https://tranquil.it/wapt
SW deployment Windows updates
IT Inventory
Arnaud Bouchez
dev @ https://tranquil.it/wapt
+7000 +400 +1 300 000
sw packages customers pc equipped
Frameworks Tuning
Frameworks Tuning
not expressiveness (yesterday)
not exhaustive
not Delphi centric
Languages & Frameworks
Performance Bottlenecks
• The Web Server
• The Database layer
• The threading/execution Model
• The RTL (JSON, heap…)
Disclaimer:
slide borrowed from yesterday’s session
Menu du jour
• The TFB Challenge
• Async Web Server
• Async Database Access
• JSON, RTTI, Mustache
The TFB Challenge
https://www.techempower.com/benchmarks
The TFB Challenge
The TFB Challenge
Web Frameworks Benchmarks
• Since 2013, a collaborative project
• Now one official round per year
• Hundredths of frameworks tested
• Seven web /endpoints tested
• 24/7 continuous tests on dedicated HW
The TFB Challenge
One official round per year
• Round 22 is just finished
• mORMot is #12 over 301 frameworks !
(with current weighting)
The TFB Challenge
Hundredths of frameworks tested
The TFB Challenge
Seven web /endpoints tested
/plaintext
/json
/db
/query?queries=###
/cached_queries?count=###
/update?queries=###
/fortunes
The TFB Challenge
Seven web /endpoints tested
• Reproduce on my dev laptop
• Compiled on Linux with Lazarus
• Run locally on the very same machine
The TFB Challenge
Gimme Numbers: Requests Per Sec
The TFB Challenge
endpoint rps% vs #1
/plaintext 99.4%
/json 91.8%
/db 59.7%
/query?queries=### 89.7%
/cached_queries?count=### 99.8%
/update?queries=### 81.5%
/fortunes 59.5%
The TFB Challenge
endpoint rps% vs #1
/plaintext 99.4%
/json 91.8%
/db single SELECT potential 59.7%
/query?queries=### 89.7%
/cached_queries?count=### 99.8%
/update?queries=### 81.5%
/fortunes 59.5%
The TFB Challenge
24/7 continuous tests on big HW
Latest runs are available at
https://tfb-status.techempower.com
The TFB Challenge
24/7 continuous tests on big HW
• Several strategies to fill all CPU cores
pin to CPU, several bound servers, threads
• Several strategies for database access
ORM, direct, async
• A lot of test & trials
guessing is usually wrong
no definitive/logical rules
The TFB Challenge
Demanding but not realistic
• Measured with wrk over a single endpoint
• Such perfect/optimal network does not exist
• Very small dataset
• No long-running tests
• No memory consumption
Async Web Server
Async Web Server
Several Web Servers
• THttpServer
1 thread per HTTP/1.1 client
thread pool for HTTP/1.0 requests (proxy)
• THttpApiServer
Windows-specific – using http.sys API
• THttpAsyncServer
thread pool for all requests
Async Web Server
Several WebSockets Servers
• TWebSocketServerRest
1 thread per WebSockets client
• THttpApiWebSocketServer
Windows-specific – using http.sys API
• TWebSocketAsyncServerRest
thread pool for all requests
Async Web Server
THttpAsyncServer
• Non-blocking read/write state machine
Using epoll API on Linux
• Based on abstract THttpAsyncConnections
HTTP-over-TCP per-connection architecture
• Optional TLS layer
with OpenSSL or Windows SSPI
and ACME/Let’s Encrypt built-in support
Async Web Server
THttpAsyncServer
• Can sustain thousands of concurrent clients
• With minimal memory/cpu consumption
• Exist as TWebSocketAsyncServerRest flavor
• THttpServer may be more reactive
for a few connections
Async Web Server
THttpAsyncServer
• Responses are computed in a thread pool
with regular blocking end-user code
• Optionally returned out-of-order
e.g. for asynchronous DB operations
• Only wake up threads if needed
to avoid syscalls on small queries
Async Web Server
THttpAsyncServer
• Avoid memory allocation
e.g. HTTP buffers reuse between connections
optional string interning of HTTP headers
• Non-blocking process
smallest possible granularity locks
Async Web Server
THttpAsyncServer
• Minimized syscalls
profiled with strace on Linux
 libc vDSO for clock_gettime()
 our own light locks with no mutex
 wakeup threads using eventfd() – only if needed
 per-second cache of date/time or timeout ticks
Async Web Server
THttpAsyncServer
• Minimized syscalls
profiled with strace on Linux
• Less optimized on Windows
Async Web Server
THttpAsyncServer
• Very efficient URI routing
with O(1) parsing of routes and parameters
• Can use the RTTI over methods
to define the endpoints
• Can redirect/rewrite URI before a REST layer
Async Web Server
THttpAsyncServer
• Perfect for the TFB use-case
top of /plaintext or /cached_queries
• Has been tuned to increase TFB numbers
also noticeable on other HW or OS
Async Web Server
mORMot 2 TFB Sample
https://github.com/synopse/mORMot2/tree/
master/ex/techempower-bench
Async Database Access
Async Database Access
PostgreSQL
• The Database of choice for TFB
• The Database of choice for most projects
Async Database Access
mormot.db.sql.postgres.pas
• Direct libpq client access
• Written from scratch
• Using mormot.db.sql.pas simplified design
cached statements with no TDataSet overhead
• Optional array binding
• Optional pipelined mode support
• Optional asynchronous / non-blocking API
Async Database Access
mORMot 2 TFB Sample
https://github.com/synopse/mORMot2/tree/
master/ex/techempower-bench
JSON, RTTI, Mustache
JSON, RTTI, Mustache
JSON
• mORMot is natively UTF-8 and JSON
on all platforms and compilers (even Delphi 7)
• mORMot 2 JSON core has been rewritten
for performance
JSON, RTTI, Mustache
Several JSON parsers
• SAX approach
• TDocVariant
• TOrmTableJson
• TDynArray
JSON, RTTI, Mustache
Several JSON parsers Delphi XE8, Win32
• SAX approach 725 MB/s
• TDocVariant 117 MB/s
• TOrmTableJson 496 MB/s
• TDynArray 332 MB/s
JSON, RTTI, Mustache
Several JSON parsers Delphi XE8, Win32
• SAX approach 725 MB/s
• TDocVariant 117 MB/s
• TOrmTableJson 496 MB/s
• TDynArray 332 MB/s
• Delphi JSON 6 MB/s
• JsonDataObjects 103 MB/s
• SuperObject 35 MB/s
• Grijjy 54 MB/s
• dwsJSON 97 MB/s
JSON, RTTI, Mustache
RTTI
• mORMot has its own RTTI cache
on all platforms and compilers
• mORMot 2 RTTI core has been rewritten
for performance and maintainability
(mORMot 1 did have duplicated logic)
JSON, RTTI, Mustache
Mustache
• mORMot has its own Mustache renderer
• mORMot 2 Mustache
can work directly on in-memory data
instead of TDocVariant containers
JSON, RTTI, Mustache
mORMot 2 TFB Sample
https://github.com/synopse/mORMot2/tree/
master/ex/techempower-bench
Frameworks Tuning
Questions? Wishes?
Opinions? Reactions?
No Marmots Were Harmed in the Making of This Session

Más contenido relacionado

Similar a EKON27-FrameworksTuning.pdf

Balázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a TunnelBalázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a Tunnel
hacktivity
 
Comet: by pushing server data, we push the web forward
Comet: by pushing server data, we push the web forwardComet: by pushing server data, we push the web forward
Comet: by pushing server data, we push the web forward
NOLOH LLC.
 
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
Balazs Bucsay
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
Trick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The ThingsTrick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The Things
Balazs Bucsay
 

Similar a EKON27-FrameworksTuning.pdf (20)

Scalable Web Apps
Scalable Web AppsScalable Web Apps
Scalable Web Apps
 
Http - All you need to know
Http - All you need to knowHttp - All you need to know
Http - All you need to know
 
A Tale of 2 Systems
A Tale of 2 SystemsA Tale of 2 Systems
A Tale of 2 Systems
 
Balázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a TunnelBalázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a Tunnel
 
Http2 in practice
Http2 in practiceHttp2 in practice
Http2 in practice
 
Membase East Coast Meetups
Membase East Coast MeetupsMembase East Coast Meetups
Membase East Coast Meetups
 
«Scrapy internals» Александр Сибиряков, Scrapinghub
«Scrapy internals» Александр Сибиряков, Scrapinghub«Scrapy internals» Александр Сибиряков, Scrapinghub
«Scrapy internals» Александр Сибиряков, Scrapinghub
 
Follow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHPFollow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHP
 
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
 
computer networking
computer networkingcomputer networking
computer networking
 
Comet: by pushing server data, we push the web forward
Comet: by pushing server data, we push the web forwardComet: by pushing server data, we push the web forward
Comet: by pushing server data, we push the web forward
 
Beyond 'Set it and Forget it': Proactively managing your EZproxy server
Beyond 'Set it and Forget it': Proactively managing your EZproxy serverBeyond 'Set it and Forget it': Proactively managing your EZproxy server
Beyond 'Set it and Forget it': Proactively managing your EZproxy server
 
Fluentd at HKOScon
Fluentd at HKOSconFluentd at HKOScon
Fluentd at HKOScon
 
Realtime web2012
Realtime web2012Realtime web2012
Realtime web2012
 
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
 
Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015
 
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (Greek)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (Greek)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
 
Trick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The ThingsTrick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The Things
 

Más de Arnaud Bouchez

Más de Arnaud Bouchez (20)

EKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdfEKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdf
 
Ekon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side NotificationsEkon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side Notifications
 
Ekon25 mORMot 2 Cryptography
Ekon25 mORMot 2 CryptographyEkon25 mORMot 2 Cryptography
Ekon25 mORMot 2 Cryptography
 
Ekon24 from Delphi to AVX2
Ekon24 from Delphi to AVX2Ekon24 from Delphi to AVX2
Ekon24 from Delphi to AVX2
 
Ekon24 mORMot 2
Ekon24 mORMot 2Ekon24 mORMot 2
Ekon24 mORMot 2
 
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMotEkon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
Ekon23 (2) Kingdom-Driven-Design applied to Social Media with mORMot
 
Ekon23 (1) Kingdom-Driven-Design
Ekon23 (1) Kingdom-Driven-DesignEkon23 (1) Kingdom-Driven-Design
Ekon23 (1) Kingdom-Driven-Design
 
High Performance Object Pascal Code on Servers (at EKON 22)
High Performance Object Pascal Code on Servers (at EKON 22)High Performance Object Pascal Code on Servers (at EKON 22)
High Performance Object Pascal Code on Servers (at EKON 22)
 
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
 
Ekon21 Microservices - SOLID Meets SOA
Ekon21 Microservices - SOLID Meets SOAEkon21 Microservices - SOLID Meets SOA
Ekon21 Microservices - SOLID Meets SOA
 
Ekon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven DesignEkon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven Design
 
Ekon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop DelphiEkon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop Delphi
 
Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
 
2016 mORMot
2016 mORMot2016 mORMot
2016 mORMot
 
A1 from n tier to soa
A1 from n tier to soaA1 from n tier to soa
A1 from n tier to soa
 
D1 from interfaces to solid
D1 from interfaces to solidD1 from interfaces to solid
D1 from interfaces to solid
 
A3 from sql to orm
A3 from sql to ormA3 from sql to orm
A3 from sql to orm
 
A2 from soap to rest
A2 from soap to restA2 from soap to rest
A2 from soap to rest
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-design
 

Último

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Último (20)

AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 

EKON27-FrameworksTuning.pdf

  • 1. Arnaud Bouchez - Synopse Frameworks Tuning
  • 2. Arnaud Bouchez • Open Source Founder mORMot 2 SynPDF, dmustache • Modern Delphi and FPC DDD, SOA, ORM, MVC Performance, SOLID • Synopse https://synopse.info
  • 3. Arnaud Bouchez dev @ https://tranquil.it/wapt SW deployment Windows updates IT Inventory
  • 4. Arnaud Bouchez dev @ https://tranquil.it/wapt +7000 +400 +1 300 000 sw packages customers pc equipped
  • 6. Frameworks Tuning not expressiveness (yesterday) not exhaustive not Delphi centric
  • 7. Languages & Frameworks Performance Bottlenecks • The Web Server • The Database layer • The threading/execution Model • The RTL (JSON, heap…) Disclaimer: slide borrowed from yesterday’s session
  • 8. Menu du jour • The TFB Challenge • Async Web Server • Async Database Access • JSON, RTTI, Mustache
  • 11. The TFB Challenge Web Frameworks Benchmarks • Since 2013, a collaborative project • Now one official round per year • Hundredths of frameworks tested • Seven web /endpoints tested • 24/7 continuous tests on dedicated HW
  • 12. The TFB Challenge One official round per year • Round 22 is just finished • mORMot is #12 over 301 frameworks ! (with current weighting)
  • 13. The TFB Challenge Hundredths of frameworks tested
  • 14. The TFB Challenge Seven web /endpoints tested /plaintext /json /db /query?queries=### /cached_queries?count=### /update?queries=### /fortunes
  • 15. The TFB Challenge Seven web /endpoints tested • Reproduce on my dev laptop • Compiled on Linux with Lazarus • Run locally on the very same machine
  • 16. The TFB Challenge Gimme Numbers: Requests Per Sec
  • 17. The TFB Challenge endpoint rps% vs #1 /plaintext 99.4% /json 91.8% /db 59.7% /query?queries=### 89.7% /cached_queries?count=### 99.8% /update?queries=### 81.5% /fortunes 59.5%
  • 18. The TFB Challenge endpoint rps% vs #1 /plaintext 99.4% /json 91.8% /db single SELECT potential 59.7% /query?queries=### 89.7% /cached_queries?count=### 99.8% /update?queries=### 81.5% /fortunes 59.5%
  • 19. The TFB Challenge 24/7 continuous tests on big HW Latest runs are available at https://tfb-status.techempower.com
  • 20. The TFB Challenge 24/7 continuous tests on big HW • Several strategies to fill all CPU cores pin to CPU, several bound servers, threads • Several strategies for database access ORM, direct, async • A lot of test & trials guessing is usually wrong no definitive/logical rules
  • 21. The TFB Challenge Demanding but not realistic • Measured with wrk over a single endpoint • Such perfect/optimal network does not exist • Very small dataset • No long-running tests • No memory consumption
  • 23. Async Web Server Several Web Servers • THttpServer 1 thread per HTTP/1.1 client thread pool for HTTP/1.0 requests (proxy) • THttpApiServer Windows-specific – using http.sys API • THttpAsyncServer thread pool for all requests
  • 24. Async Web Server Several WebSockets Servers • TWebSocketServerRest 1 thread per WebSockets client • THttpApiWebSocketServer Windows-specific – using http.sys API • TWebSocketAsyncServerRest thread pool for all requests
  • 25. Async Web Server THttpAsyncServer • Non-blocking read/write state machine Using epoll API on Linux • Based on abstract THttpAsyncConnections HTTP-over-TCP per-connection architecture • Optional TLS layer with OpenSSL or Windows SSPI and ACME/Let’s Encrypt built-in support
  • 26. Async Web Server THttpAsyncServer • Can sustain thousands of concurrent clients • With minimal memory/cpu consumption • Exist as TWebSocketAsyncServerRest flavor • THttpServer may be more reactive for a few connections
  • 27. Async Web Server THttpAsyncServer • Responses are computed in a thread pool with regular blocking end-user code • Optionally returned out-of-order e.g. for asynchronous DB operations • Only wake up threads if needed to avoid syscalls on small queries
  • 28. Async Web Server THttpAsyncServer • Avoid memory allocation e.g. HTTP buffers reuse between connections optional string interning of HTTP headers • Non-blocking process smallest possible granularity locks
  • 29. Async Web Server THttpAsyncServer • Minimized syscalls profiled with strace on Linux  libc vDSO for clock_gettime()  our own light locks with no mutex  wakeup threads using eventfd() – only if needed  per-second cache of date/time or timeout ticks
  • 30. Async Web Server THttpAsyncServer • Minimized syscalls profiled with strace on Linux • Less optimized on Windows
  • 31. Async Web Server THttpAsyncServer • Very efficient URI routing with O(1) parsing of routes and parameters • Can use the RTTI over methods to define the endpoints • Can redirect/rewrite URI before a REST layer
  • 32. Async Web Server THttpAsyncServer • Perfect for the TFB use-case top of /plaintext or /cached_queries • Has been tuned to increase TFB numbers also noticeable on other HW or OS
  • 33. Async Web Server mORMot 2 TFB Sample https://github.com/synopse/mORMot2/tree/ master/ex/techempower-bench
  • 35. Async Database Access PostgreSQL • The Database of choice for TFB • The Database of choice for most projects
  • 36. Async Database Access mormot.db.sql.postgres.pas • Direct libpq client access • Written from scratch • Using mormot.db.sql.pas simplified design cached statements with no TDataSet overhead • Optional array binding • Optional pipelined mode support • Optional asynchronous / non-blocking API
  • 37. Async Database Access mORMot 2 TFB Sample https://github.com/synopse/mORMot2/tree/ master/ex/techempower-bench
  • 39. JSON, RTTI, Mustache JSON • mORMot is natively UTF-8 and JSON on all platforms and compilers (even Delphi 7) • mORMot 2 JSON core has been rewritten for performance
  • 40. JSON, RTTI, Mustache Several JSON parsers • SAX approach • TDocVariant • TOrmTableJson • TDynArray
  • 41. JSON, RTTI, Mustache Several JSON parsers Delphi XE8, Win32 • SAX approach 725 MB/s • TDocVariant 117 MB/s • TOrmTableJson 496 MB/s • TDynArray 332 MB/s
  • 42. JSON, RTTI, Mustache Several JSON parsers Delphi XE8, Win32 • SAX approach 725 MB/s • TDocVariant 117 MB/s • TOrmTableJson 496 MB/s • TDynArray 332 MB/s • Delphi JSON 6 MB/s • JsonDataObjects 103 MB/s • SuperObject 35 MB/s • Grijjy 54 MB/s • dwsJSON 97 MB/s
  • 43. JSON, RTTI, Mustache RTTI • mORMot has its own RTTI cache on all platforms and compilers • mORMot 2 RTTI core has been rewritten for performance and maintainability (mORMot 1 did have duplicated logic)
  • 44. JSON, RTTI, Mustache Mustache • mORMot has its own Mustache renderer • mORMot 2 Mustache can work directly on in-memory data instead of TDocVariant containers
  • 45. JSON, RTTI, Mustache mORMot 2 TFB Sample https://github.com/synopse/mORMot2/tree/ master/ex/techempower-bench
  • 46. Frameworks Tuning Questions? Wishes? Opinions? Reactions? No Marmots Were Harmed in the Making of This Session