简体   繁体   English

为什么12 Factor应用程序应该自包含?

[英]Why should a 12 Factor app be self contained?

In the 12 Factor article on Port Binding http://12factor.net/port-binding there is a requirement that every app be self-contained and not have a runtime injected eg Tomcat. 在关于端口绑定的12 Factor文章http://12factor.net/port-binding中 ,要求每个应用程序都是自包含的,并且没有注入运行时,例如Tomcat。 For what reason is this advised... what are advantages of self-contained apps for microservices? 出于什么原因建议...微服务的自包含应用程序的优点是什么?

To understand rules around port binding and self-contained apps, it's helpful to view things from the perspective of the platforms designed to run 12-factor apps, like Heroku or Deis . 要了解有关端口绑定和自包含应用程序的规则,从设计用于运行12因素应用程序的平台(如HerokuDeis)的角度来看是很有帮助的。

These platforms are scaling applications at the process level. 这些平台正在流程级别扩展应用程序。 When processes are scaled up, the platform tries to place these additional workers behind the routing mesh so they can start serving traffic. 当进程按比例放大时,平台会尝试将这些额外的工作人员放在路由网格后面,以便他们可以开始提供流量。 If the app is not self-contained and, for example, is tightly coupled to a front-end Apache server using mod_jk -- it is not possible to scale by running more isolated worker processes. 如果应用程序不是自包含的,并且例如使用mod_jk紧密耦合到前端Apache服务器 - 则无法通过运行更多孤立的工作进程来扩展。

Port binding exists to solve the problem of "port brokering" at the platform level. 存在端口绑定以解决平台级别的“端口代理”问题。 If every application worker listened on port 80 there would be conflicts. 如果每个应用程序工作者在端口80上进行侦听,则会发生冲突。 To solve this, port binding is a convention whereby the application listens on a port the platform has allocated -- and which is passed in as a $PORT environment variable. 为了解决这个问题,端口绑定是一种约定,通过该约定,应用程序侦听平台已分配的端口 - 并将其作为$PORT环境变量传入。 This ensures a) the application worker listens on the right port and b) the platform knows where to route traffic destined for that worker. 这确保了a)应用程序工作者侦听正确的端口并且b)平台知道将路由到该工作者的流量路由到何处。

I think is because it gives you a great deal of flexibility when the time to scale up your app comes. 我认为这是因为它可以在您扩展应用程序时提供极大的灵活性。 If you use tomcat you'll have to copy your .war and drop it inside another tomcat and then load balance your requests to either of them. 如果您使用tomcat,则必须复制.war并将其放入另一个tomcat中,然后将请求负载平衡到其中任何一个。

Instead If your app has a self contained http server, you colud just run another instance in another port and forget about all that tomcat stuff. 相反,如果你的应用程序有一个自包含的http服务器,你就可以在另一个端口运行另一个实例而忘记所有tomcat的东西。 You would still have to load balance your requests to either of your app instances, but seems more straight forward. 您仍然需要将您的请求负载平衡到任一应用实例,但似乎更直接。

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

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