REST API或“直接"远程Celery/Django工作者的数据库访问权限? [英] REST API or "direct" database access for remote Celery/Django workers?

查看:47
本文介绍了REST API或“直接"远程Celery/Django工作者的数据库访问权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,该项目将在美国不同位置的机器上有多位芹菜工人,这些机器将通过Internet进行通信.

I'm working on a project that will have multiple celery workers on machines in different locations in the US that will communicate over the internet.

我最好将Django项目分配到每台计算机上,并使用数据库凭据将它们配置到我的数据库主机上,还是应该有一个主要" Django/数据库主机来为远程芹菜任务和工作人员提供一个REST API,以便命中数据库访问权限?

Am I better off distributing my Django project to each machine and configuring them with the database credentials to my database host, or should I have a "main" Django/database host that presents a REST API for remote celery tasks and workers to hit for the database access?

主要在寻找优点/缺点以及我没有想到的任何因素.

Mostly looking for pros/cons and any factors I haven't thought of.

我可以提供一个简单的API端点,该端点提供我的任务需要查询的所有数据,而一个简单的POST API端点可以创建我的任务需要创建的所有数据库条目.

I can provide single simple API endpoints that provide all the data my tasks need to query and simple POST API endpoints that can create all the database entries my tasks need to create.

我最多只能说10个远程工作人员,它们可能总共每分钟执行1个请求.

I'll have no more than say 10 remote workers that would maybe altogether being doing 1 request per minute.

我认为这可能意味着我所关心的不是请求/响应开销,而是更多的可维护性,体系结构,安全性...

I'm thinking this probably means my concerns are not so much about the request/response overhead but more about maintainability, architecture, security...

推荐答案

答案取决于太多的变量,关注点,作用力以及诸如此类的东西,而不仅仅是取决于...".

The answer depends on too many variables, concerns, forces and whatnots to be anything else than "it depends...".

我认为您已经考虑过以下优点和缺点,但是无论如何:

I assume you already thought of the following pros and cons, but anyway:

使用API​​将明显延长请求/响应周期,并给Django项目(前端服务器,应用服务器等)带来相当大的负担.同样,这意味着您的任务将无法使用所有数据库功能(复杂的查询,聚合等).

Using an API will make for longer request/response cycles (obviously) and put quite some load on the Django project (front server, app server etc). Also it means that your tasks won't be able to use all of the database features (complex queries, aggregations, whatever).

OTHO添加API层会将工作人员与内部db模式隔离开,这可以使迁移(在Django方面)和部署更加容易,因为您不必停止所有工作人员,部署到所有人并重新启动工作人员.好吧,它甚至可以在不影响工作人员的情况下更改API方面的技术(不是我有很多理由这样做,但无论如何...).但这也意味着您需要维护一个完整的API,并且模型更改(或其中的最后一部分)很可能会影响您的API和/或您的任务代码(如果更改涉及添加工作人员应使用的功能)等).

OTHO adding an API layer will isolate the workers from the inner db schema, which can make migrations (on the Django side) and deployment easier as you won't have to stop all the workers, deploy to everyone and restart the workers. Well it even makes it possible to change the API side technology without impacting the workers (not that I see much reason to do so but anyway...). But it also mean you have a whole API to maintain, and chances are that model changes - or at last part of them - will impact your API and/or your tasks code anyway (if the changes are about adding features that the workers should use etc).

IOW确实取决于(是的,我已经说过了,不是吗?)取决于您项目的需求和约束,只有您/您的团队知道哪种解决方案最适合您的项目.

IOW, it really depends (yeah, I already said so, didn't I ?) on your project's needs and constraints, and only you/your team know which solution will best match your project.

这篇关于REST API或“直接"远程Celery/Django工作者的数据库访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆