samdark / yii2-cookbook

Yii 2.0 Community Cookbook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling assets for scaling

samdark opened this issue · comments

For https://github.com/samdark/yii2-cookbook/blob/master/book/scaling.md it's necessary to describe on how to deal with assets.

There is one more issue though. For non session-sticky load balancing, you might fail finding an asset.

Let's say 1st request hit server A, the asset will be generated in the local storage inside server A. And then when the 2nd request sent to get the asset but hit server B which hasn't generated the asset, it will return 404.

My suggestion are

  1. Use shared storage or NFS to store the storage.
  2. Compile the assets using yii asset in build process and store it in centralized storage like AWS S3.
  3. Or create new assset manager class that can check cache or centralized storage and then generate the asset on the fly if not exists.

Or you can just configure the load balancer to use session-sticky.

Good suggestions. Do you have time to include these into the article?

Working on it. Now that there is a topic about scaling. I think I haven't found any topic about continuous integration. Might be useful.

Absolutely. Would be great if you'll share your experience.

i run an api for user creation so avatars and user photos are created in production so shared storage, google cloud storage is necessary. May i know how it can be configured so all the servers have a central storage on google cloud storage.

Second @chizuoka request. I am using google app engine flex custom environment, everything works great, the last issue is sharing user generated content (such as, for example, avatars) via a single google cloud storage across horizontally scaled VM's with stateless Yii2 application. Any pointers would be appreciated so that I could develop it myself.

If we could have a pluggable storage AssetManager class, for example with creocoder/yii2-flysystem, then all our problems would be solved.

That's something for Yii 3.0.