英文:
Azure App Service and long running task for multi tenancy application
问题
我正在构建支持长时间运行任务的多租户Web应用程序。这些任务将消耗更多的CPU/RAM资源:
- 从Azure SQL中按租户读取员工列表。
- 使用
Parallel.ForEach
执行每个员工列表的多任务操作。 - 长时间计算每个员工(每个员工都是一个任务)。
- 将员工数据保存到Azure SQL。
- 推送通知到客户端浏览器。
Web应用程序将部署在Azure应用服务上。
这些任务将需要更多时间完成(大约30分钟或更长)。如果两个租户的用户同时执行任务,会导致服务器资源不足(CPU/RAM)。如果我有100个或更多租户,情况将变得更糟。
有一个解决方案,后来的租户将不得不等待前一个租户的任务完成。但是,客户肯定不会同意这种情况。
所以我的问题是:是否有任何Azure服务可以用于运行这种长时间运行的过程,而租户不必互相等待?或者可以为我提供解决方案吗?Azure应用服务的扩展功能是其中一种解决方案,对吗?
英文:
I am building the Multi Tenancy Web Application that has long running task. This task will take more CPU/RAM:
- Read list of employee by Tenant from Azure SQL.
- Use
Parallel.ForEach
to perform multi task per employee list. - Long running calculating per employee (each employee is one task).
- Save employee data to Azure SQL.
- Push notification to client browser.
The Web Application will be deployed on Azure App Service.
The task will take more time to complete (about 30 minutes and more). If 2 users from 2 tenants perform the task at the same time, there will be insufficient server resources(CPU/RAM). If I have 100 or more tenants, things get worse.
There is one solution, the tenant who comes in later will have to wait for the previous tenant's task to complete. However, it is certain that the customer will not agree.
So my question: Is there any Azure service I can use to run this long-running process where tenants will not have to wait for each other? Or can give me a solution for this? The Azure App Service scale out feature is one of the solution, isn't it?
答案1
得分: 1
是的,你可以利用Azure App服务的扩展功能,根据负载来扩展你的应用程序。如果来自多个租户的用户正在执行任务,Web应用程序将根据负载和你在自动扩展功能中配置的规则自动进行扩展。
有两种配置自动扩展的方法:自动缩放 和 自动扩展。在自动缩放中,你可以根据应用程序实例扩展的规则进行配置,而自动扩展功能目前处于预览阶段,它会根据你的Web应用程序的行为自动扩展你的应用程序。
手动扩展你的实例如下:
自动扩展如下:
除了扩展功能,你还可以使用Web作业来在后台运行长时间运行的任务,Web作业将使用与你的Web应用程序运行在同一实例上的相同实例:
方法2)
另一种方法是使用Azure批处理服务来运行长时间运行的任务。
参考此 .Net API示例 来使用Azure Batch服务运行长时间运行的任务。
英文:
> The Azure App Service scale out feature is one of the solution, isn't it?
Yes, You can make use of Azure App service scale out feature, To Scale your app according to the load. If users from multiple tenants are performing the task. The Web app will automatically scale based on the load and the rule you have configured in the Auto scale feature.
There are two ways to configure the auto scaling. Auto-scale and Automatic scaling. In auto scale you provide the rules on based on which the App instances are scaled out and Automatic Scaling feature is in preview it scales out your app based on the behaviour of your web app.
Manually scale your instances like below:-
Auto-scale like below:-
For enabling Automatic scaling which I'd recommend for your workload, You need to have your App service in Premium plan. If you enable Automatic scaling you are not required to have Auto scaling rule like above, Automatic scaling will scale your app automatically based on its behaviour.
You can configure Always ready instance these are the instances which are running and ready to serve the requests when required. Maximum burst is the number of instances the app can be scaled out to.
Along with Scale out feature you can make use of Webjobs to run the long running tasks in the background, Web jobs will use the same instances of app service your Web app is running on:-
Method 2)
One more method is to use Azure batch service to run your long running task.
Refer this .Net API example to run long running task using Azure Batch service.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论