如何处理Heroku中耗时的Python功能?

发布于 2025-01-21 14:20:53 字数 249 浏览 2 评论 0原文

我已经成功地使用Postgres将Django应用程序部署到Heroku。唯一的问题是,我编写的一些Python功能可能需要长达几分钟的时间来运行(数据用硒刮擦许多页面并使用Keras生成50种不同的深度学习模型)。如果花费超过30秒,则应用程序崩溃。我最终计划使用此Heroku应用程序作为API,它将使用Netlify上的React将其连接到前端。有没有办法以某种方式在幕后自动运行这些功能?如果没有,我该如何部署一个在后端中运行耗时python功能的网站并将React用于前端?

I have successfully deployed a Django app to Heroku using Postgres. The only problem is that some of the python functions I have written can take up to several minutes to run (data scraping many pages with selenium and generating 50 different deep learning models with keras). If it takes longer than 30 seconds the app crashes. I ultimately plan on using this Heroku app as an API that I will connect to a frontend using React on netlify. Is there a way to automatically run these functions behind the scenes somehow? If not, how can I deploy a website that runs time consuming python functions in the backend and uses React for the frontend?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆消瘦 2025-01-28 14:20:53

好的,我认为我们可以将问题分为两个部分:\

1- Heroku Free Tier(假设它是在缺席30分钟后“杀死”服务器(

2-您可能需要重新设计架构。创建偶尔训练此机器学习模型的服务器又如何消耗这些模型?您还可以将废物零件与实际服务器分开,只需从数据库中提取数据即可。

由于您没有对问题添加限制,因此我会这样。

Okay, I think we can divide the problems in TWO parts:\

1- Heroku free Tier (assuming it is) "kills" the server after 30min of absence (source), so basically its very difficult to host a backend in heroku. And besides that, since you're training A LOT of deep learning models you could go out of memory and things like that.

2- You might want to redesign your architecture. What about creating a server that once in a while train this machine learning models and the other one just consume and make inferences on those models? You could also separate the scrapping part from the actual server, and just pull data from db.

Since you didn't added constraints to your problem, I see it that way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文