0

I have written a service that reads from the file system in order to determine state, and holds that state for a while instead of constantly updating the file system. Therefore it's paramount that there is only one instance of that service. Now it seems Web Apps instantiates two instances of a Flask service by default.

Is this a documented thing, or have I understood some configuration wrong? Are they in fact replicas or some other mechanism? And most importantly, how can I disable this feature?

My application factory:

from flask import Flask


def create():
    app = Flask(__name__)
    d = {'t': 0}

    @app.route('/', methods=['GET'])
    def main():
        d['t'] += 1
        return 'Calls: %d' % d['t'], 200

    return app

And web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
    <add key="WSGI_HANDLER" value="app.create()" />
    <add key="WSGI_LOG" value="D:\home\site\wwwroot\wsgi.log" />
  </appSettings>
  <system.webServer>
    <handlers>
        <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
        scriptProcessor="D:\home\python364x64\python.exe|D:\home\python364x64\wfastcgi.py"
        resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
</configuration>

After startup, these calls return a sequence like 1, 1, 2, 2, 3, 3... which to me indicates that there are two instances running and a balancer round-robining the two. The pattern seems to be fairly regular, not skipping the other service for example.

Felix
  • 2,548
  • 19
  • 48

2 Answers2

0

If I have understood you correctly, every Azure WebApp has an associated 'scm' service site, which runs both Kudu and other Site Extensions.

Additionally, as outlined in the GitHub page, you have the option to use the same process for the user site and the scm site or otherwise.

WEBSITE_DISABLE_SCM_SEPARATION=true - When separation enabled (the default), the main site and scm site run in different sandboxes. Some resulting behavior:

• With separation, when you stop the site, the scm site is still running, and you can continue to use git and msdeploy. • With separation, the Main and scm sites each have their own local files. So, you won't see the Main site's temp files from Kudu console. Note: Turning off separation is considered to be a legacy mode that is no longer fully supported. See the doc for more details

Kindly let me know if this is what you're looking for or something else.

AjayKumar
  • 2,812
  • 1
  • 9
  • 28
  • Hello, I don't think this is it. It doesn't matter (at least to me) whether any additional processes are run in the service. It is the apparent duplicate service that is the issue, as if WFastCGI or IIS starts up another instance of the web application. – Felix Jun 25 '19 at 05:32
0

The answer was a simple one. Applications created under a service plan may be scaled to a number of instances by default. In my case it was indeed set to two. One can view the number of instances in the application view under Scale Out.

Setting the number of instances back to one solved the issue. But in case other services under that plan require the number of instances to stay the same, creating a new service plan with no additional instances is required.

Felix
  • 2,548
  • 19
  • 48
  • You don't have to create a new service plan, with the Scale Out you could configure the Instance count to one. – George Chen Jun 26 '19 at 02:29
  • @GeorgeChen Yeah, I phrased it poorly. Of course that can be done if there are no other services under that plan. Edited the answer. – Felix Jun 26 '19 at 04:32