简体   繁体   English

从 Java 调用 Python 机器学习服务作为 OS 进程或通过 REST 的微服务

[英]Calling Python machine learning service from Java as an OS process or micro service via REST

I am building a web application for business management as a side project and i face an architecture problem.我正在构建一个用于业务管理的 Web 应用程序作为一个副项目,我面临一个架构问题。 My application will be an Angular web client communicating with a kotlin/java spring back-end via REST.我的应用程序将是一个 Angular Web 客户端,通过 REST 与 kotlin/java spring 后端进行通信。 One of the modules of the application will be time series forecasting of sales/orders, and because of the ease of development and the piles of documentation that exists online, i want to build that module in python.该应用程序的模块之一将是销售/订单的时间序列预测,并且由于开发的简便性和在线存在的大量文档,我想用 python 构建该模块。 That module will generate dynamic html plots that i want to serve to the client.该模块将生成我想要提供给客户端的动态 html 图。 So my question is, it would be better if i do the python part as a stand alone rest micro service with Flask or it's ok to just put the python code inside the java project and call it using ProcessBuilder?所以我的问题是,如果我使用 Flask 将 python 部分作为一个独立的休息微服务来做会更好,或者可以将 python 代码放在 java 项目中并使用 ProcessBuilder 调用它? Thanks in advance :)提前致谢 :)

My view will be to create a microservice with Python Flask with certain REST endpoints for obtaining the results and let java application interact with python based microservice for machine learning.我的观点是使用 Python Flask 创建一个带有某些 REST 端点的微服务以获取结果,并让 java 应用程序与基于 python 的微服务交互以进行机器学习。 The main advantage with this approach will be the separation of concern and deployment will be independent and you can leverage the benefits of microservice architecture.这种方法的主要优点是关注点分离和部署将是独立的,您可以利用微服务架构的优势。

Although it is also possible to bundle python code inside java or you can use jython, any changes in either in java code or in python code will add extra overhead for deployment.尽管也可以将 python 代码捆绑在 java 中,或者您可以使用 jython,但在 java 代码或 python 代码中的任何更改都会增加部署的额外开销。 Bundling additional non java code will be another overhead for different OS systems like Windows, Mac and Linux.捆绑额外的非 Java 代码将是 Windows、Mac 和 Linux 等不同操作系统系统的另一项开销。

You can check the following links for reference.您可以查看以下链接以供参考。

https://www.datacamp.com/community/tutorials/machine-learning-models-api-python https://www.datacamp.com/community/tutorials/machine-learning-models-api-python

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

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