samdark / yii2-cookbook

Yii 2.0 Community Cookbook
1.45k stars 296 forks source link

Handling assets for scaling #116

Open samdark opened 8 years ago

samdark commented 8 years ago

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

samdark commented 8 years ago

A static path is required: http://www.yiiframework.com/doc-2.0/yii-web-assetmanager.html#%24hashCallback-detail

petrabarus commented 8 years ago

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.
petrabarus commented 8 years ago

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

samdark commented 8 years ago

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

petrabarus commented 8 years ago

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.

samdark commented 8 years ago

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

chizuoka commented 7 years ago

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.

gusev-genotek commented 7 years ago

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.

razvanphp commented 5 years ago

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

samdark commented 5 years ago

That's something for Yii 3.0.