App Engine: Few big scripts or many small ones?

后端 未结 3 2085
一生所求
一生所求 2020-12-12 04:40

I am working on a website that I want to host on App Engine. My App Engine scripts are written in Python. Now let\'s say you could register on my website and have a user pro

3条回答
  •  离开以前
    2020-12-12 04:58

    A single big script would have to be loaded every time an instance for your app starts, possibly hurting the instance start time, the response time of every request starting an instance and the memory footprint of the instance. But it can handle any request immediately, no additional code needs to be loaded.

    Multiple smaller scripts can be lazy-loaded, on demand, after your app is started, offering advantages maybe appealing to some apps:

    • the main app/module script can be kept small, which keeps the instance startup time short
    • the app's memory footprint can be kept smaller, handler code in lazy-loaded files is not loaded until there are requests for such handlers - interesting for rarely used handlers
    • the extra delay in response time for a request which requires loading the handler code is smaller as only one smaller script needs to be loaded.

    Of course, the disadvantage is that some requests will have longer than usual latencies due to loading of the handler scripts: in the worst case the number of affected requests is the number of scripts per every instance lifetime.

    Updating a user profile is not something done very often, I'd consider it a rarely used piece of functionality, thus placing its handlers in a separate file looks appealing. Splitting it into one handler per file - I find that maybe a bit extreme. It's really is up to you, you know better your app and your style.

    From the GAE (caching) infra perspective - the file quota is 10000 files, I wouldn't worry too much with just ~100 files.

提交回复
热议问题