Date post: | 17-Feb-2017 |
Category: |
Technology |
Upload: | fwdays |
View: | 290 times |
Download: | 5 times |
PHP at Scale:Knowing enough to be dangerous!
Oleksii PetrovSkelia Ukraine / ETWater
Who am ISystem ArchitectTeam LeadPHP Developer
Find me on@alexhelkar
alexhelkar
https://github.com/alexhelkar
What does it mean"to scale"?
Does it mean?
Or does it mean?
Often it means
"To scale"Improve system metrics
without changing thesystem*
* (dramaticaly)
Scale roadmap is predefinedby your stack and software architecture
Let's go!
PerformanceStory
PHP 7 factsisset 1.55 times faster than array_key_existsis_file 26 times faster than file_existssingle quotes slower that double quotesinstanceof faster is_aetc.
Code performance?
Blackfire.io & Symfony Blog
Current results:Total request time: 18.4 msfile_exists called: 7 timesExec. time for file_exists: 460 µs Expected results:Exec/ time: ~17.6 µsTotal request time: ~18.3996 ms
PHP lang performance
...овно?
OR
...амно?
Why a system isslow?
Because ofDatabase!
Scaling strategiesCachingQueueingReads/Writes SplitingSharding
Caching
Typical Request Flow
DB Cache
Application Cache
Web Cache
Cache: Rule of thumb
IF Application is SLOWEnable Caching
IF Application has GLITCHESDisable Caching
Queueing
Queue as The Equalizer
Queue as The Equalizer
Problems?
Delays
Queue as Load Balancer
Problems?
Unboundedbuffers!
Read/Write Splitting
Master-Slave replicationasync/semi-sync
Writes
Reads Reads
Problems?
Replication lag
Galera Replicationaka sync replication
Problems?
WritesPerformance
What is IoT?
IoT is like
CanvasREST APIWeather DataAvg. Request Size 325b
Data Sample{ "deviceId": 231, "lat":"45.22838254", "lng":"-114.23725403", "timestamp":1459509524, "temperature":2.99, "precipProbability":0.386, "humidity":0.055, "pressure":1035.617}
Load GeneratorYandex Tank
TasksCreate platform setupGather performance metricsCalculate budgets
Plan 1: 86k req/day (1 rps)
Plan 2: 8.64M req/day (100 rps)
Setup: 20$
Response Time
Limitation
Same Setup: 200rps
Why 3 databaseservers?
Probability?
Head: 50% | Tails: 50%
Probability of 2 consecutive Heads?
25%
Probability of 3 consecutive Heads?
12.5% 0.5^3
Servers reliability
1 Server 99%
10 Servers 90.4%
100 Servers 36.6%
Distributed System
High Availability
Any
should consider
Plan 4: 43.2M req/day (500rps)
Setup Variant 1: 380$
Quantiles
Setup Variant 2: 150$
Quantiles
Mircoservices230 Reasons to choose
380$ - 150$ = 230$
Plan 5: 84.6M req/day (1k rps)
Plan 5: 84.6M req/day (1k rps)
Plan 6: 432M req/day (5k rps)
Started to thinkabout bulk inserts?
Plan 7: 1.26B req/day (15k rps)
Quantiles
TCP/IP
TCP Flow
Packets Rate
Packets Rate
1 Request
15k Requests
~10 Packets
~15k Packets
Load Balancer Trick
Load Balancer Trick
Load Balancer Trick
Load Balancer Trick
Why?
Load Balancer Trick
75k pack.
75k pack.
LB Recieved: 150k packets
Plan 7: 50000 req/sec
CommodityHardware
Commodity Hardware
$5 Server 1 CPU
20 CPU $100 Server
$640 Server
c4.8xlarge: $1222.750/monthly
DNS Load Distribution
DNS Load Distribution
DNS Cache
Rule of Thumb: Add LB
What if?
Floating IP
Sharding?Last Resort
Mysql: Manual Sharding
Mysql: Fabric (pre-alpha)<?php
$mysqli = new mysqli("myapp", "user", "password", "database");
mysqlnd_ms_fabric_select_shard($mysqli, "test.fabrictest", 10);$mysqli->query("INSERT INTO fabrictest(id) VALUES (10)");
mysqlnd_ms_fabric_select_shard($mysqli, "test.fabrictest", 10);$mysqli->query("SELECT id FROM test WHERE id = 10");
http://php.net/manual/ru/mysqlnd-ms.quickstart.mysql_fabric.php
MariaDB: Spider
Mysql Cluster (NDB)
MongoDB Sharding
Apache Cassandra
RabbitMQHits 1 Million Messages Per
Second. 32 machines
https://blog.pivotal.io/pivotal/products/rabbitmq-hits-one-million-messages-per-
second-on-google-compute-engine
Apache Kafka2 Million Writes Per Second
3 machines
https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-
second-three-cheap-machines
Instead SummaryScalability as afterwords doesn't workDatabase is not a queueDatabase is not a lock systemRedis is not a queueLoad balancers as a mustLinear disk writes winsPerfomance in PHP is done by everything except PHPBeing distributed is freaking hard
Questions?
Find me on@alexhelkar
alexhelkar
https://github.com/alexhelkar