2016-08-12 15:24
浏览 19


One my customers has very strict requirements about how they can deploy a web application. They require it to be deploy-able as WAR within a Java server like Tomcat. Our application however is written in golang and compiles into an executable server.

The only solution I could think off would be to start a long lived golang process in the background which listens on a non-standard port like 8080 and then put some kind of a proxy in java which would transparently proxy all HTTP requests and responses to this process.

How should I go about implementing this ? I'm not at all familiar with Java Servlets and running long running processes like this in the background.

My main concern is if something like this is standard,

  1. would it affect the JVM's memory usage, etc ?
  2. Would the server allow my golang process to allocate the required amount of memory ?
  3. Would the JVM be able to track it's processor utilization ?

Is there a better way to do this maybe ? Like some kind of inter-process communication mechanism ?

图片转代码服务由CSDN问答提供 功能建议

我的一个客户对如何部署Web应用程序有非常严格的要求。 他们要求它可以作为Java服务器(例如Tomcat)中的WAR进行部署。 但是,我们的应用程序是用golang编写的,并编译为可执行服务器。

我唯一想到的解决方案是在后台启动一个长寿命的golang进程,该进程在非标准端口(如 8080)上侦听 ,然后在Java中放入某种代理,它将透明地代理所有HTTP请求和对此过程的响应。

我应该如何实现呢?我一点都不熟悉Java Servlet,并且在后台运行长时间运行的进程。


  1. 会影响JVM的内存使用率,等等吗? li>
  2. 服务器是否允许我的golang进程分配所需的\内存量?
  3. JVM是否能够跟踪其处理器利用率? < / ol>

    也许有更好的方法吗? 就像某种进程间通信机制一样?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyaosi3164 2016-08-16 20:49

    If HTTP is the only API your Go application exposes, then you're only left with the option to just send a HTTP request to Go. Yes you can start the Go executable as a child process from the JVM using a ProcessBuilder. But that's not truly embedding go within your WAR. You can use JNI (Go bindings are called GoJVM) to invoke native routines in Go from Java, but then you have to make a lot of adjustments to your Go code base as well.

    What you are looking probably for is indeed a reverse proxy. It's not frequently done in servlets / application servers, because this is usually done in load balancers already. So usually that would be NGINX or httpd with mod_rewrite. For application servers, you can use a proxy servlet.


    The memory footprint is usually not to bad, because you're essentially only connecting the streams. The JVM will be able to track processor and memory utilisation - if implemented properly and the Go executable runs on the same server. Obviously the Java specific statistics don't make much sense anymore, as you're only using your Java server as a pass-through.

    Sounds like you will be in trouble though. If my strict requirement was a WAR-archive that can be deployed to an application server, I wouldn't accept another executable added to my stack. Reverse proxied or not.

    打赏 评论
  • doushi1960 2016-08-22 20:13

    If they want war, give them war!

    Write a thin layer web service that has the executable embedded as a resource that executes it to bring up the go server and accepts web calls and does a pass through to the go service.

    Achieves nothing I hear you say? Well, neither does their arbitrary requirement that was probably put in place by someone who's long since left the company, and/or because they lack the confidence/experience/ knowledge to operationally deal with other forms of deployment. There is no particularly good reason to deny your service to be deployed except the work required to establish proper operational procedures (laziness).

    Just follow the letter of their rules, not the spirit, and be honest if asked about your implementation. They won't mind.

    This may sound like a rant, but IMHO and experience, this kind of approach is reality and the drivers for the requirement are emotionally based, so a somewhat emotional answer is warranted.

    打赏 评论

相关推荐 更多相似问题