简体   繁体   English

用于长时间运行的计划作业的Azure资源类型

[英]Azure resource types for long running, scheduled jobs

I have a .NET Core Console Application that I need to deploy to Azure and schedule to run once a day. 我有一个.NET Core Console应用程序,我需要将其部署到Azure并安排每天运行一次。 The application is creating a TCP Socket to get market data. 该应用程序正在创建TCP Socket以获取市场数据。 I need to schedule it to run in the morning, and the application will receive a close message near the end of the day from the market and automatically close. 我需要安排它在早上运行,应用程序将在当天结束时从市场收到一条关闭消息并自动关闭。 Approximately run time is estimated at 16 hours, 5 days a week. 大约运行时间估计为每周5天,每天16小时。

Here are the option I've looked researched: 以下是我研究过的选项:

  • Cloud Service, which might be deprecated (I'm having a hard to validating the comments I've read to this effect) Cloud Service,可能会被弃用(我很难验证我读过的评论)
  • Service Fabric - but this really looks like it's tailored for stateless applications that can spin up and down for scale. Service Fabric - 但这看起来非常适合无状态应用程序,可以按比例缩小规模。 In my case, it should always be a single instance (I do like the self "healing", if my service does go down, it would be great if it is automatically restarted or a new one is spun up) 在我的情况下,它应该总是一个单独的实例(我喜欢自我“愈合”,如果我的服务确实失败了,如果它自动重启或新的旋转会很好)
  • Azure Web job and azure scheduler. Azure Web作业和azure调度程序。 It looks like I could set this to "always on" and add a settings file that has cron configuration , but it seems like a waste of resources to have it "always on". 看起来我可以将其设置为“始终打开”并添加具有cron配置的设置文件 ,但是将它“永远打开”似乎浪费资源。 This option also appears to be limited in it's deployment options - I can't set up (that I see) a git integration and auto-deploy. 此选项似乎也受限于它的部署选项 - 我无法设置(我看到)git集成和自动部署。 This does seem like the way to g o 这似乎是g o 的方式

I'm looking for the pro's and con's of these options above for my use case, or any other options that I might have missed. 我正在寻找上面这些选项的专业人士和骗子,用于我的用例,或者我可能错过的任何其他选项。

There's one thing that seems to be overlooked here. 这里有一件事似乎被忽略了。 This part: 这部分:

The application is creating a TCP Socket to get market data. 该应用程序正在创建TCP Socket以获取市场数据。

Is that 80/TCP or 443/TCP? 是80 / TCP还是443 / TCP? Does it talk HTTP over one of those ports? 它是否通过其中一个端口与HTTP通信? Because if your application talks custom protocol over an arbitrary TCP port, you can't use WebJobs . 因为如果您的应用程序通过任意TCP端口谈论自定义协议,则无法使用WebJobs The App Service sandbox does not allow arbitrary port binding. App Service沙箱不允许任意端口绑定。 This applies ingress . 这适用于入口 Egress (outbound), there's no restriction. 出口(出境),没有限制。 You can make raw TCP requests from the WebJob to any destination and port. 您可以 WebJob向任何目标和端口发出原始TCP请求。

From https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#network-endpoint-listening : 来自https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#network-endpoint-listening

Network endpoint listening 网络端点监听

The only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports; 通过互联网访问应用程序的唯一方法是通过已经公开的HTTP(80)和HTTPS(443)TCP端口; applications may not listen on other ports for packets arriving from the internet. 应用程序可能无法在其他端口上侦听来自Internet的数据包。

There's no need to involve the Azure Scheduler service. 无需涉及Azure Scheduler服务。 WebJobs have a built-in cron implementation which is completely free. WebJobs有一个完全免费的内置cron实现

Also, the Always On feature really means hit this site with synthetic requests every couple minutes so it serves a 200 OK, and thus prevent the Application Pool from being unloaded from memory due to inactivity. 此外, Always On功能实际上意味着每隔几分钟就会使用合成请求访问此站点,因此它可以提供200 OK,从而防止应用程序池因不活动而从内存中卸载。

I would use the tank . 我会用坦克 Can't find anything wrong with the tank if you can pick your tank size . 如果您可以选择坦克大小,则无法找到坦克的任何问题。 There's also very little maintenance with tanks. 坦克的维护也很少。

 Size (id) Cores Ram Net Bandwidth Total disk size --------------------------------------------------------------- ExtraSmall 1 0.75 GB Low 19 GB Small 1 1.75 GB Moderate 224 GB ... 

ServiceDefinition.csdef if you need to listen on a socket: 如果你需要监听套接字,请使用ServiceDefinition.csdef

<Endpoints>
  <InputEndpoint name="aRawTCPEndpoint" protocol="tcp" port="54321" localPort="54321" />
</Endpoints> 

Where does your application keep state? 您的申请在哪里保持状态? Memory/disk/off-the-box database? 内存/磁盘/现成的数据库? Cloud Service roles are stateless in nature and if one instance gets sick it's barbecued and a new one is spun up. 云服务角色本质上是无状态的,如果一个实例生病,它会被烧烤并且新的角色会被启动。 It's crucial that state be kept off-the-box, in durable storage - Blob/Table storage, Azure SQL, DocumentDB, etc. 在持久存储中保持开箱即用状态至关重要 - Blob / Table存储,Azure SQL,DocumentDB等。

Imagine you've build your house 6 years ago. 想象一下,你在6年前建造了自己的房子。 And you've used this material called ClassicBrick in the structure. 而且你在结构中使用了名为ClassicBrick的材料。 It is a good material, strong, waterproof, scratch-resistant. 它是一种很好的材料,坚固,防水,防刮。 But recently this newer and better material - let's call it Armritis (which by the way is designed to be used in BRIDGES not houses, but i digress) came out which everybody tells you is better in every way. 但是最近这个更新更好的材料 - 让我们称它为Armritis (顺便设计用于BRIDGES,而不是房子,但我离题),每个人都告诉你,它在各方面都更好。 Do you tear down the house? 你拆掉房子了吗? Cloud Services are not deprecated and until i see an official Microsoft roadmap telling the opposite i'm not going to entertain this in any way. 云服务并没有被弃用,直到我看到微软的官方路线图告诉相反的情况,我不会以任何方式接受这一点。

On the topic of Service Fabric , it CAN do stateful and it's actually one of its biggest selling points: 关于Service Fabric的主题,它可以做有状态的,它实际上是它最大的卖点之一:

From https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-quick-start/ : 来自https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-quick-start/

Create a stateful service 创建有状态服务

Service Fabric introduces a new kind of service that is stateful. Service Fabric引入了一种有状态的新服务。 A stateful service can maintain state reliably within the service itself, co-located with the code that's using it. 有状态服务可以在服务本身内可靠地维护状态,与使用它的代码位于同一位置。 State is made highly available by Service Fabric without the need to persist state to an external store. Service Fabric提供高可用状态,而无需将状态持久保存到外部存储。

Azure Functions is also worth a good look if you can speak HTTP over standard ports. 如果您可以通过标准端口说HTTP,那么Azure功能也值得一看。

First, we need to compare the pricing between Cloud Service, Service Fabric, Web job &Scheduler if you doesn't want to wast resources. 首先,如果您不想浪费资源,我们需要比较Cloud Service,Service Fabric,Web job和Scheduler之间的定价。 Here is the pricing calculator. 是定价计算器。 Because your console application job will have special scheduler time to work. 因为您的控制台应用程序作业将具有特殊的调度程序时间。 It is better to save money if the job is not work. 如果工作不起作用,最好省钱。 So, Web job(if you have web app meantime) &Scheduler will be good choice to achieve your purpose. 所以,Web工作(如果你有web应用程序)和Scheduler将是实现你的目的的好选择。

Using a cloud service for such a tiny job is like using a tank to go to work 使用云服务完成这么小的工作就像使用坦克去上班一样

Service Fabric is mainly for building Micro-services style application not a console apps or jobs that run once a day Service Fabric主要用于构建微服务样式应用程序,而不是每天运行一次的控制台应用程序或作业

Web Jobs require a web app, so you have the remaining option which is the base for web jobs. Web Jobs需要一个Web应用程序,因此您有剩余的选项,它是Web作业的基础。

You can create the scheduler and make it run every day at specific time or execute it manually on demand 您可以创建调度程序并使其在特定时间每天运行或按需手动执行

I would go with either one solution, in this priority: 我会选择一个解决方案,优先考虑:

  1. App Service: Web Apps (Web Job)
  2. Virtual Machine
  3. Cloud Service

App Service: Web Apps (Web Job) provides a free plan. App Service: Web Apps (Web Job)提供免费计划。 And it started to support Web Jobs in a free plan. 它开始在免费计划中支持Web Jobs You will be able to work with files, should you need it. 如果需要,您将能够处理文件。 Just as mentioned in other answers, just set a scheduler . 正如其他答案中所提到的,只需设置一个scheduler If you have doubts and think it is not kosher to do it on a website, then think of it as getting a free website (if you use paid plan) as a bonus. 如果您有疑问并认为在网站上进行此操作并不是犹太人 ,那么可以将其视为获得免费网站(如果您使用付费计划)作为奖励。 Either way, everything runs on a machine - be it with web-server or without. 无论哪种方式,一切都在一台机器上运行 - 无论是web服务器还是没有。 Maybe you will even start some long-ago-forgotten web project of yours? 也许你甚至会开始一些很久以前被遗忘的网络项目?

Cloud Service and Virtual Machine are both straightforward and simple. Cloud ServiceVirtual Machine既简单又简单。 Gotta be honest, I haven't used Cloud Service , yet I think you can connect to it via Remote Desktop just like to an ordinary VM. 说实话,我还没有使用过Cloud Service ,但我认为你可以通过Remote Desktop连接它,就像普通的VM一样。 You will have complete control. 你将完全控制。 I would choose Virtual Machine over the Cloud Service though, just because it is cheaper. 我会选择Virtual Machine而不是Cloud Service ,因为它更便宜。

Solutions that will NOT work: 解决方案不起作用:

Azure Scheduler does not fit you, because it allows only HTTP/S requests and posting messages to Azure Storage queues, Azure Service Bus queues, or Azure Service Bus . Azure Scheduler不适合您,因为它仅允许HTTP / S请求并将消息发布到Azure存储队列,Azure Service Bus队列或Azure Service Bus

Personally I would go with a WebJob without AlwaysOn, and use Azure Scheduler to fire the WebJob at the desired times using HTTPS. 我个人会使用没有AlwaysOn的WebJob,并使用Azure Scheduler使用HTTPS在所需的时间触发WebJob。 Then the WebJob can do the calls needed to get the data. 然后WebJob可以执行获取数据所需的调用。 This does not need AlwaysOn since the Scheduler call wakes it up anyway. 这不需要AlwaysOn,因为调度程序调用无论如何都会唤醒它。

Azure Functions might also be worth a look, though they aren't meant for long-running tasks. Azure功能也可能值得一看,但它们不适用于长时间运行的任务。

This would also probably be the cheapest option as the Web App can probably run on Free tier (depending on how long the job takes) and the Scheduler can also be Free tier. 这也可能是最便宜的选项,因为Web App可能在Free层上运行(取决于作业需要多长时间),而Scheduler也可以是Free tier。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM