2. Hi Everyone!
I am Petra Novandi
Now serves as
Chief Technology Officer at
UrbanIndo.com
-
Contact me at
Email:
petra.barus@gmail.com
Twitter:
@petrabarus
3. UrbanIndo & Yii
- Use Yii 1.1 at 2011
- Migrate to Yii 2.0 at 2015
- Contribute to Yii core
- #7435 #8933 #9249 #9277
- Contribute to Yii2 plugins
- yii2-queue, yii2-s3-cache, yii2-dynamodb
11. Continuous
Availability/Redundancy
No single point of failure
Cost/Performance
Flexibility
Not being locked by the
hardware
WHY SCALE OUT?
Continuous Upgrade
Without downtime
Geographical
Distribution
Access to nearest node
12. Multi-servers environment concerns in Yii2
Database
Assets
Load Balancing
File System
Session
Deployment
And many more… Logging, Cache, Queue,
Batch Processings.
Let’s discuss that on another occasion..
I don’t have enough time.. :(
15. Sticky Sessions
Requests from same client
will be forwarded to same
instance
Load Balancer Session Types
Non-Sticky Sessions
Requests from same client
can be forwarded to
different instances.
18. » No need a lot of configuration in the Yii side
» Although you might want to have concerns in
⋄ hostInfo in the yiiwebUrlManager
⋄ ipHeaders in yiiwebRequest (upcoming Yii
2.0.13), different proxies can have different headers
26. ❏ Since PHP stores session in file system
we need to store it outside the instance
❏ Similar like database
❏ Use classes like yiimongodbSession,
yiiredisSession,
yiiwebDbSession,
yiiwebCacheSession,
28. Some Considerations
» Better use key-value storage type that stores in
memory instead of files
⋄ E.g. Redis, memcached
⋄ Or SQL that support memory storage
⋄ MySQL’s MEMORY storage engine
» Execute Session::gcSession() using cron.
36. Asset Management in Single Server
» Hash is not deterministic due to filemtime()
(yiiwebAssetManager::hash)
» Different server can have different filemtime()
39. Multiple Server With Consistent Hash
/var/www/web/assets/1234567890/script.js
/var/www/web/assets/1234567890/script.js
40. A Much Better Way
1. Build and compress the assets in build
server
2. Upload assets to central storage (e.g. S3)
3. Put a CDN in front of the storage
42. Pros
1. No need additional
local process to
generate assets
(Reduced request
time)
2. Optimized assets
3. Served through CDN
Cons
1. Need build server
2. Need central storage
3. Need CDN
4. Build can be slow
47. Some Considerations
» Composer installation after code pull
» Asset installation, build, compress after code pull
» Load balancer request draining before code
symlink
» Local cache clean up
» JIT warming up (if using HHVM)
» Health check for load balancer
» Blue-green deployment