Who am I
System Architect
Team Lead
PHP Developer
Find me on
@alexhelkar
alexhelkar
https://github.com/alexhelkar
Performance
Story
Canvas
- PHP 7.0.8
- Digital Ocean 5$ Droplet
- Symfony 3 Demo Application
- Yandex Tank
[phantom]
address=555.166.5.74 ; fake ip
port=80 ;target port
rps_schedule=step(20, 60, 10, 30s) const(1, 30s) ;load scheme
uris = /ru/blog/
Yandex Tank Config
Results
Results
- Max. stable RPS: 50
- Response time: ~20ms
PHP 7 facts
- isset 1.55 times faster than array_key_exists
- is_file 26 times faster than file_exists
- single quotes slower that double quotes
- instanceof faster is_a
- etc.
Code performance?
Blackfire.io profile
Current results:
Total request time: 18.4 ms
file_exists called: 7 times
Exec. time for file_exists: 460 µs
Expected results:
Exec/ time: ~17.6 µs
Total request time: ~18.3996 ms
Perfomance
Response time?
Requests per second?
PHP lang performance
...овно?
OR
...амно?
SLA
Story
Demo App
recall with $$
Infrastructures scaling
5$
RAM: 512
CPU: 1
HDD: 20
50 RPS
App Server
10$
50 RPS
App Server
RAM: 1024
CPU: 1
HDD: 30
50 RPS
App Server
RAM: 512
CPU: 1
HDD: 20
LB Server
RAM: 512
CPU: 1
HDD: 20
15$
100 RPS
App Server
50 RPS
App Server
LB Server
5$
App Server
RAM: 512
CPU: 1
HDD: 20
RAM: 512
CPU: 1
HDD: 20
RAM: 512
CPU: 1
HDD: 20
RAM: 1024
CPU: 1
HDD: 30
20$
160 RPS
App Server
120 RPS
App Server
LB Server
App Server
App Server
RAM: 2048
CPU: 2
HDD: 40
RAM: 512
CPU: 1
HDD: 20
RAM: 512
CPU: 1
HDD: 20
RAM: 512
CPU: 1
HDD: 20
RAM: 512
CPU: 1
HDD: 20
Summary
- Often hardware is cheaper than software
- Often scaling is cheaper than tuning
- Often horizontal scaling wins vertical scaling
- Often applications are not scalable :(
Load Balancer Pattern
Examples
- Kubernetes Services
- Microservices
- etc
Good to know
- HAProxy TCP and HTTP Load Balancing
- Nginx HTTP Load Balancing
- Message Queue-Based Load Balancing
MQ Balancing
Story
MQ Balancing
Consumer retries
API Gateway
Benefits we've got
- Advanced routing of requests
- Advanced routing of responses
- Workers could be added dynamically without LB reconfig
- Buffer size by queue limit
- Back pressure by message TTL
Scaling out
Story
Generic Web App
Perfomance
Requests per second
(concurrency)
DNS Load Distribution
DNS Load Distribution
DNS Cache
Rule of Thumb: Add LB
What if?
Floating IP
Perfomance
Response time
(reads)
Reads Flow
DB Cache
Application Cache
Application Cache Candidates
- Memcached (sessions, k/v data)
- sessions
- k/v data
- Redis
- k/v data
- leaderboards
- durability
- replication
* Manual sharding both cases
Web Cache
Cache: Rule of thumb
IF Application is SLOW
Enable Caching
IF Application has GLITCHES
Disable Caching
Perfomance
Response time
(writes)
Cirquit Breaker
Fire & Forget
MySQL
Database Perfomance
MySQL
Story of 100 servers
MongoDB
Chose correct sharding key
Apache Cassandra
Linear writes
Apache Cassandra
Life story
Apache Kafka
2 billions messages on 3 machines
Distributed Locks
Consul || etcd || Zookeeper
Instead Summary
- Scalability as afterwords doesn't work
- Database is not a queue
- Database is not a lock system
- Redis is not a queue
- MySQL master is always SPOF
- Load balancers as a must
- Linear disk writes wins
- Perfomance in PHP is done by everything except PHP
- Being distributed is fucking hard
Questions?
Find me on
@alexhelkar
alexhelkar
https://github.com/alexhelkar
PHP at Scale: System Architect Toolbox
By Oleksii Petrov
PHP at Scale: System Architect Toolbox
- 485