Azure Web App多个实例混乱

dax*_*axu 0 azure azure-web-sites

我有一个Web应用程序,该应用程序有两个默认实例,从资源管理器中可以看到有两个实例。但是,在global.asax代码中,我有以下代码:

public class LogEntity : TableEntity
    {
        public LogEntity(string partitionKey, string rowKey)
        {
            this.PartitionKey = partitionKey;
            this.RowKey = rowKey;
        }
        public LogEntity() { }
        public string Submitter { get; set; }
    }

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        Random ran = new Random();
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
        var tableClient = storageAccount.CreateCloudTableClient();
        CloudTable table = tableClient.GetTableReference("logs");
        table.CreateIfNotExists();

        var key1 = ran.Next();
        var machineName1 = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");

        LogEntity log1 = new LogEntity(Environment.MachineName + ":" + machineName1 + ":" + key1.ToString(), "instance started");
        TableBatchOperation batchOperation1 = new TableBatchOperation();
        batchOperation1.Insert(log1);
        table.ExecuteBatch(batchOperation1);

    }
}
Run Code Online (Sandbox Code Playgroud)

但是,从我的azure表日志中,我只能看到生成的一个日志条目,并且它始终来自同一实例。

这是否意味着当我有多个实例时,只有一个实例会调用application_start?我认为所有实例都应该独立运行,因此都应该点击application_start。但是,我的日志似乎与我的理解相矛盾。

更新

我显示了记录到天蓝色表的代码。我的期望是,由于有两个实例,我应该看到在azure表中创建了两个日志条目。但是,总是只有一个条目。

dax*_*axu 5

我在Microsoft支持下进行了一些讨论,并了解了现在的原因。

对于我的站点,启用了ARR Affinity,并启用了该设置,azure负载均衡器将仅启用已访问的负载(作为Affinity cookie)。结果,我只看到我的代码运行一次。

当我禁用Affinity时,azure负载均衡器将立即启用所有实例,并且我看到我的代码在所有实例上运行。