SlideShare a Scribd company logo
1 of 25
Download to read offline
DON'T YOU
(FORGET
ABOUT ME)
PHP Meetup Lisboa 2023
Things developers forget to
remember not to forget
Talk by Bernd Alter
PHP Meetup Lisboa 2023
Bernd Alter
Co-CTO at Turbine Kreuzberg GmbH
Twitter: @bazoo0815
Experience:
years developer
years PHP
years eCommerce
years Spryker
25+
20+
10+
7+
PHP Meetup Lisboa 2023
DEVELOPERS
ONLY CARE ABOUT
FUNCTIONALITY
PHP Meetup Lisboa 2023
"WORKS ON MY MACHINE"
DATABASE
Local development
❏ small dataset
❏ queries are fast
❏ no memory issues
❏ no latency
❏ indexes don't really matter
Production system
❏ large(r) dataset
❏ queries are slower
❏ memory/load issues
❏ large(r) latency between services/components
❏ missing indexes (can) slow down queries
PHP Meetup Lisboa 2023
"WORKS ON MY MACHINE"
TRAFFIC
Production system
❏ (huge) traffic
❏ concurrency
❏ blocking requests
❏ lack of resources
Local development
❏ no traffic (it's just you!)
❏ single requests/processes
❏ no concurrency
❏ all resources just for you
PHP Meetup Lisboa 2023
POSSIBLE SOLUTIONS
❏ SCALING
❏ PERFORMANCE OPTIMIZATION
❏ CACHING
PHP Meetup Lisboa 2023
SCALING
Easy solution:
Throw more resources at it!
Downside:
❏ more complex orchestration
❏ increasing infrastructure costs
(resources + devops ⇒ money)
PHP Meetup Lisboa 2023
What do you consider a large dataset
in your day-to-day business?
(quick show of hands)
100.000 entries?
1.000.000 entries?
10.000.000 entries?
100.000.000 entries?
more?
DATABASE PERFORMANCE
PHP Meetup Lisboa 2023
Consider payload size of query result set
❏ transfer time matters
❏ only fetch data you need
❏ limit columns in SELECT
Example: table with ~1.200 rows, total size 42 MB, avg row size ~40kB
250ms
3.5 s
DATABASE PERFORMANCE
vs
(=14x faster)
select * from myTable;
select id from myTable;
PAYLOAD SIZE
PHP Meetup Lisboa 2023
Set proper indexes
❏ analyze your queries, not your tables
(EXPLAIN is your friend!)
❏ use composite indexes
DATABASE PERFORMANCE
INDEX ANALYSIS/OPTIMIZATION
Remember: TANSTAAFL!
❏ 'no free lunch' principle: indexes come at a cost
❏ avoid large/many indexes on tables with many write operations
❏ avoid unnecessary indexes
CREATE INDEX myIndex ON myTable (lastname, firstname);
✔ SELECT * FROM myTable WHERE lastname = ‘Smith’ AND firstname = ‘John’;
✔ SELECT * FROM myTable WHERE lastname = ‘Smith’;
✖ SELECT * FROM myTable WHERE firstname = ‘John’ and lastname = ‘Smith’;
✖ SELECT * FROM myTable WHERE firstname = ‘John’;
Index used for queries:
← size order matters!
PHP Meetup Lisboa 2023
Common approach: LIMIT/OFFSET
❏ query performance is bad
Use keyset pagination (or seek pagination)
❏ no read-ahead needed
❏ only required rows are fetched/read
+ constant execution time
+ real pagination (no missed entries)
− only previous/next page (no page jumps)
DATABASE PERFORMANCE
KEYSET/CURSOR PAGINATION
PHP Meetup Lisboa 2023
Common approach: LIMIT/OFFSET
❏ query performance is bad
Use keyset pagination (or seek pagination)
❏ no read-ahead needed
❏ only required rows are fetched/read
+ constant execution time
+ real pagination (no missed entries)
− only previous/next page (no page jumps)
DATABASE PERFORMANCE
KEYSET/CURSOR PAGINATION
PHP Meetup Lisboa 2023
DATABASE PERFORMANCE
KEYSET/CURSOR PAGINATION
PHP Meetup Lisboa 2023
Don't hit the database at all (or at least less)
❏ use bulk operations over single operations
❏ select as much data at once as possible
❏ Common Table Expressions (CTE)
❏ UPSERTs for write operations
❏ avoid unnecessary queries
DATABASE PERFORMANCE
INSERT INTO myTable (...) VALUES (...) ON DUPLICATE KEY UPDATE SET ...; (MySQL)
ON CONFLICT (...) DO UPDATE SET ...; (Postgres)
PHP Meetup Lisboa 2023
CACHING
For how long? ❏ as long as possible
❏ usually trade-off between up-to-dateness and performance
How? ❏ prepare data (aggregate/transform)
❏ in-process caching (in PHP: static (member) variables)
❏ browser-caching
❏ key-value storage (e.g. Memcache, Redis)
❏ reverse proxy (e.g. Varnish)
What? ❏ time-/resource-consuming operations
❏ often used/requested data
PHP Meetup Lisboa 2023
5 days?
5 hours?
5 min?
5 sec?
CACHING
What would you consider a reasonable
amount of time to cache for?
(quick show of hands)
PHP Meetup Lisboa 2023
Even short caching periods (TTL) can boost your application’s performance significantly
CACHING
HOW LONG?
Example: Universal Music community chat (~2008)
❏ simple iframe with latest 50 messages
❏ ajax-reload every 10s
❏ ~1.000 concurrent users
⟶ ~6.000 req/min
PHP Meetup Lisboa 2023
Even short caching periods (TTL) can boost your application’s performance significantly
CACHING
HOW LONG?
Solution:
❏ local file cache with TTL of 5s
Example: Universal Music community chat (~2008)
❏ simple iframe with latest 50 messages
❏ ajax-reload every 10s
❏ ~1.000 concurrent users
⟶ ~6.000 req/min
—> 12 req/min (500x less)
PHP Meetup Lisboa 2023
CACHING
❏ ensure fast, responsive experience for all users
❏ use stale-while-revalidate mechanism
(supported by all modern browsers)
❏ after first caching, all users get always
(sufficiently) up-to-date data
ADVANCED TECHNIQUES
PHP Meetup Lisboa 2023
Try to make all your non-production environments as production-like as possible:
DEVELOP PRODUCTION-LIKE
❏ replicate infrastructure in development, testing and staging environments
❏ use Docker
❏ ideal: use same components/services in exactly same version and resources (CPU, memory, etc.)
❏ at least: use same components/services in same major version and similar resources
❏ use production-like dataset for development and staging/testing
❏ ideal: complete anonymized/pseudonymized production dump (-->GDPR!)
❏ at least: similar amount of data for crucial entities, e.g. products, prices, customers in ecommerce
PHP Meetup Lisboa 2023
There is no such thing as 'another production system'
DEVELOP PRODUCTION-LIKE
DISCLAIMER
You cannot duplicate your production system.
Period.
Live with it …
❏ traffic is different
❏ state of data is different
❏ services/components have different versions
❏ …
PHP Meetup Lisboa 2023
FEATURE TRAP
❏ also work on:
❏ tech debt
❏ updates
❏ refactoring
❏ maintenance tasks
❏ no immediate, but long-term business value
❏ stand up to your PO or stakeholders!
"WE HAVE TO BUILD FEATURES,
WE DON'T HAVE TIME FOR OTHER STUFF"
PHP Meetup Lisboa 2023
LINKS
❏ Use The Index, Luke
❏ No offset: We need tool support for keyset pagination
❏ SQL CTE (WITH Clause): The Ultimate Guide - Database Star
❏ Staleness and revalidation
❏ GitHub - DivanteLtd/anonymizer: Universal tool to anonymize database
❏ Blackfire.io - PHP profiling tool
PHP Meetup Lisboa 2023
QUESTIONS?
PHP Meetup Lisboa 2023
FOR LISTENING!

More Related Content

Similar to Don't you (forget about me) - PHP Meetup Lisboa 2023

My Database Skills Killed the Server
My Database Skills Killed the ServerMy Database Skills Killed the Server
My Database Skills Killed the ServerColdFusionConference
 
SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBUniFabric
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...javier ramirez
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseBlack Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseTim Vaillancourt
 
Challenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on HadoopChallenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on HadoopDataWorks Summit
 
Lunch & Learn BigQuery & Firebase from other Google Cloud customers
Lunch & Learn BigQuery & Firebase from other Google Cloud customersLunch & Learn BigQuery & Firebase from other Google Cloud customers
Lunch & Learn BigQuery & Firebase from other Google Cloud customersDaniel Zivkovic
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukValeriy Kravchuk
 
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...it-people
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.Vlad Fedosov
 
Challenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop EngineChallenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop EngineNicolas Morales
 
Cost architecting for Windows Azure - NDC2011
Cost architecting for Windows Azure - NDC2011Cost architecting for Windows Azure - NDC2011
Cost architecting for Windows Azure - NDC2011Maarten Balliauw
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringAndrew Kirkpatrick
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the ServerdevObjective
 

Similar to Don't you (forget about me) - PHP Meetup Lisboa 2023 (20)

My Database Skills Killed the Server
My Database Skills Killed the ServerMy Database Skills Killed the Server
My Database Skills Killed the Server
 
SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DB
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseBlack Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
 
Challenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on HadoopChallenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on Hadoop
 
Lunch & Learn BigQuery & Firebase from other Google Cloud customers
Lunch & Learn BigQuery & Firebase from other Google Cloud customersLunch & Learn BigQuery & Firebase from other Google Cloud customers
Lunch & Learn BigQuery & Firebase from other Google Cloud customers
 
Ad505 dev blast
Ad505 dev blastAd505 dev blast
Ad505 dev blast
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
 
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
 
pm1
pm1pm1
pm1
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.
 
Challenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop EngineChallenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop Engine
 
Cost architecting for Windows Azure - NDC2011
Cost architecting for Windows Azure - NDC2011Cost architecting for Windows Azure - NDC2011
Cost architecting for Windows Azure - NDC2011
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability Engineering
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 

Recently uploaded

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Don't you (forget about me) - PHP Meetup Lisboa 2023

  • 1. DON'T YOU (FORGET ABOUT ME) PHP Meetup Lisboa 2023 Things developers forget to remember not to forget Talk by Bernd Alter
  • 2. PHP Meetup Lisboa 2023 Bernd Alter Co-CTO at Turbine Kreuzberg GmbH Twitter: @bazoo0815 Experience: years developer years PHP years eCommerce years Spryker 25+ 20+ 10+ 7+
  • 3. PHP Meetup Lisboa 2023 DEVELOPERS ONLY CARE ABOUT FUNCTIONALITY
  • 4. PHP Meetup Lisboa 2023 "WORKS ON MY MACHINE" DATABASE Local development ❏ small dataset ❏ queries are fast ❏ no memory issues ❏ no latency ❏ indexes don't really matter Production system ❏ large(r) dataset ❏ queries are slower ❏ memory/load issues ❏ large(r) latency between services/components ❏ missing indexes (can) slow down queries
  • 5. PHP Meetup Lisboa 2023 "WORKS ON MY MACHINE" TRAFFIC Production system ❏ (huge) traffic ❏ concurrency ❏ blocking requests ❏ lack of resources Local development ❏ no traffic (it's just you!) ❏ single requests/processes ❏ no concurrency ❏ all resources just for you
  • 6. PHP Meetup Lisboa 2023 POSSIBLE SOLUTIONS ❏ SCALING ❏ PERFORMANCE OPTIMIZATION ❏ CACHING
  • 7. PHP Meetup Lisboa 2023 SCALING Easy solution: Throw more resources at it! Downside: ❏ more complex orchestration ❏ increasing infrastructure costs (resources + devops ⇒ money)
  • 8. PHP Meetup Lisboa 2023 What do you consider a large dataset in your day-to-day business? (quick show of hands) 100.000 entries? 1.000.000 entries? 10.000.000 entries? 100.000.000 entries? more? DATABASE PERFORMANCE
  • 9. PHP Meetup Lisboa 2023 Consider payload size of query result set ❏ transfer time matters ❏ only fetch data you need ❏ limit columns in SELECT Example: table with ~1.200 rows, total size 42 MB, avg row size ~40kB 250ms 3.5 s DATABASE PERFORMANCE vs (=14x faster) select * from myTable; select id from myTable; PAYLOAD SIZE
  • 10. PHP Meetup Lisboa 2023 Set proper indexes ❏ analyze your queries, not your tables (EXPLAIN is your friend!) ❏ use composite indexes DATABASE PERFORMANCE INDEX ANALYSIS/OPTIMIZATION Remember: TANSTAAFL! ❏ 'no free lunch' principle: indexes come at a cost ❏ avoid large/many indexes on tables with many write operations ❏ avoid unnecessary indexes CREATE INDEX myIndex ON myTable (lastname, firstname); ✔ SELECT * FROM myTable WHERE lastname = ‘Smith’ AND firstname = ‘John’; ✔ SELECT * FROM myTable WHERE lastname = ‘Smith’; ✖ SELECT * FROM myTable WHERE firstname = ‘John’ and lastname = ‘Smith’; ✖ SELECT * FROM myTable WHERE firstname = ‘John’; Index used for queries: ← size order matters!
  • 11. PHP Meetup Lisboa 2023 Common approach: LIMIT/OFFSET ❏ query performance is bad Use keyset pagination (or seek pagination) ❏ no read-ahead needed ❏ only required rows are fetched/read + constant execution time + real pagination (no missed entries) − only previous/next page (no page jumps) DATABASE PERFORMANCE KEYSET/CURSOR PAGINATION
  • 12. PHP Meetup Lisboa 2023 Common approach: LIMIT/OFFSET ❏ query performance is bad Use keyset pagination (or seek pagination) ❏ no read-ahead needed ❏ only required rows are fetched/read + constant execution time + real pagination (no missed entries) − only previous/next page (no page jumps) DATABASE PERFORMANCE KEYSET/CURSOR PAGINATION
  • 13. PHP Meetup Lisboa 2023 DATABASE PERFORMANCE KEYSET/CURSOR PAGINATION
  • 14. PHP Meetup Lisboa 2023 Don't hit the database at all (or at least less) ❏ use bulk operations over single operations ❏ select as much data at once as possible ❏ Common Table Expressions (CTE) ❏ UPSERTs for write operations ❏ avoid unnecessary queries DATABASE PERFORMANCE INSERT INTO myTable (...) VALUES (...) ON DUPLICATE KEY UPDATE SET ...; (MySQL) ON CONFLICT (...) DO UPDATE SET ...; (Postgres)
  • 15. PHP Meetup Lisboa 2023 CACHING For how long? ❏ as long as possible ❏ usually trade-off between up-to-dateness and performance How? ❏ prepare data (aggregate/transform) ❏ in-process caching (in PHP: static (member) variables) ❏ browser-caching ❏ key-value storage (e.g. Memcache, Redis) ❏ reverse proxy (e.g. Varnish) What? ❏ time-/resource-consuming operations ❏ often used/requested data
  • 16. PHP Meetup Lisboa 2023 5 days? 5 hours? 5 min? 5 sec? CACHING What would you consider a reasonable amount of time to cache for? (quick show of hands)
  • 17. PHP Meetup Lisboa 2023 Even short caching periods (TTL) can boost your application’s performance significantly CACHING HOW LONG? Example: Universal Music community chat (~2008) ❏ simple iframe with latest 50 messages ❏ ajax-reload every 10s ❏ ~1.000 concurrent users ⟶ ~6.000 req/min
  • 18. PHP Meetup Lisboa 2023 Even short caching periods (TTL) can boost your application’s performance significantly CACHING HOW LONG? Solution: ❏ local file cache with TTL of 5s Example: Universal Music community chat (~2008) ❏ simple iframe with latest 50 messages ❏ ajax-reload every 10s ❏ ~1.000 concurrent users ⟶ ~6.000 req/min —> 12 req/min (500x less)
  • 19. PHP Meetup Lisboa 2023 CACHING ❏ ensure fast, responsive experience for all users ❏ use stale-while-revalidate mechanism (supported by all modern browsers) ❏ after first caching, all users get always (sufficiently) up-to-date data ADVANCED TECHNIQUES
  • 20. PHP Meetup Lisboa 2023 Try to make all your non-production environments as production-like as possible: DEVELOP PRODUCTION-LIKE ❏ replicate infrastructure in development, testing and staging environments ❏ use Docker ❏ ideal: use same components/services in exactly same version and resources (CPU, memory, etc.) ❏ at least: use same components/services in same major version and similar resources ❏ use production-like dataset for development and staging/testing ❏ ideal: complete anonymized/pseudonymized production dump (-->GDPR!) ❏ at least: similar amount of data for crucial entities, e.g. products, prices, customers in ecommerce
  • 21. PHP Meetup Lisboa 2023 There is no such thing as 'another production system' DEVELOP PRODUCTION-LIKE DISCLAIMER You cannot duplicate your production system. Period. Live with it … ❏ traffic is different ❏ state of data is different ❏ services/components have different versions ❏ …
  • 22. PHP Meetup Lisboa 2023 FEATURE TRAP ❏ also work on: ❏ tech debt ❏ updates ❏ refactoring ❏ maintenance tasks ❏ no immediate, but long-term business value ❏ stand up to your PO or stakeholders! "WE HAVE TO BUILD FEATURES, WE DON'T HAVE TIME FOR OTHER STUFF"
  • 23. PHP Meetup Lisboa 2023 LINKS ❏ Use The Index, Luke ❏ No offset: We need tool support for keyset pagination ❏ SQL CTE (WITH Clause): The Ultimate Guide - Database Star ❏ Staleness and revalidation ❏ GitHub - DivanteLtd/anonymizer: Universal tool to anonymize database ❏ Blackfire.io - PHP profiling tool
  • 24. PHP Meetup Lisboa 2023 QUESTIONS?
  • 25. PHP Meetup Lisboa 2023 FOR LISTENING!