运行 Python 代码很长一段时间

huangapple go评论68阅读模式
英文:

Running python code over a lond period of time

问题

  • Google服务器的免费层是否足够满足我的需求?
  • 我应该购买哪个树莓派/哪个微型电脑?
  • 除了这些选项以外,还有其他建议吗?
英文:

I want to run a python code continually over a long period of time like 2/3 Months without checking on it.

Regarding the code, it requests data from a plataform using their api,processes it and sends a POST to make changes on my account on the plataform (also it runs each 15/30 minutes).

I was thinking using a server (google cloud) or a Raspberry Pi but i dont have experience in using any of them so my questions is as follows.

TLDR of questions:

-is google server free tier enough for what i want?
-Which raspberry pie should i get/Which microcomputer should i get?
-any other ideas besides these?

答案1

得分: 1

在Google Cloud上有多个产品。

我建议使用他们的无服务器产品之一。我推荐无服务器,这样你只需关注你的代码,而不必担心启动虚拟机、配置它和维护它。

对于他们的无服务器产品,我认为你应该看看Google App Engine(GAE)和Cloud Run(即在它们之间选择)。如果你熟悉容器或更喜欢容器,那就选择Cloud Run,否则使用GAE。

由于你需要按计划定期运行你的代码,你还需要Cloud SchedulerCloud Tasks,它们允许你设置一个调度以调用或发起对托管在GAE或Cloud Run上的应用的URL的调用。

Scheduler和Tasks之间的区别在这里有文档记录。

英文:

There are multiple products on Google Cloud.

I would suggest using one of their serverless offerings. I recommend serverless so that you only focus on your code and don't have to worry about spinning up a virtual machine, configuring it and maintaining it.

For their serverless offering, I think you should look at Google App Engine (GAE) and Cloud Run (i.e. choose between one of them). If you're familiar with or prefer containers, then go with Cloud Run else use GAE.

Since you need to run your code on a regular schedule, you'll also need Cloud Scheduler or Cloud Tasks which allows you to set a schedule for invoking or making a call to the url of your app hosted on GAE or Cloud Run.

Difference between Scheduler and Tasks is documented here

答案2

得分: 1

您可以考虑使用Compute Engine,您可以在其上配置和运行您的Python代码。然而,您需要负责在虚拟机上安装Python及其必要的依赖项以运行您的代码。

另一个值得考虑的适当产品是Cloud Functions,它是一个无服务器计算平台,允许您运行事件驱动的代码,而无需担心服务器管理。它会根据流入的流量自动扩展,确保您的代码可以高效处理负载。此外,您只需支付在执行函数期间使用的计算资源。

在设计和部署代码时,请考虑功能超时、内存要求和任何必要的依赖关系。

GCP的免费层包括一定数量的使用量,可用于运行您的代码而不产生额外费用。由于免费层对CPU数量、内存和网络出口的使用有一定限制,请注意管理您的虚拟机实例。

查看此文档以了解不同产品的免费层包含内容:

文档链接

英文:

You can consider Compute Engine that you can configure and run your Python code on. However, you are in charge of installing Python and its necessary dependencies on the VM to run your code.

A suitable product to also consider is Cloud Functions which is a serverless compute platform that allows you to run event-driven code without worrying about server management. It automatically scales based on the incoming traffic, ensuring that your code can handle the load efficiently. Additionally, you only pay for the compute resources used during the execution of your function.

Consider factors like function timeouts, memory requirements, and any necessary dependencies when designing and deploying your code as a Cloud Function

The free tier on GCP includes a limited amount of usage that can be utilized for running your code without incurring additional costs.
As the free tier has certain limitations on the number of CPUs, memory, and network egress that you can consume. Also, be aware that the free tier has time limits on VM usage, so make sure to manage your VM instances accordingly.

Check out this documentation for the free tier inclusions for different products

huangapple
  • 本文由 发表于 2023年6月29日 01:25:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575447.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定