I'd love to hear more about replacing tomcat. Can you lead me to some info material on that topic. In our company we rely heavily on application servers, faster alternatives are always worth checking out.
Sure. Let me try to share some details. But before that, just want to make a point (which you surely know) that its also a major decision of a language change from Java to Go.
In the Tomcat/Jetty/<any other Java app server> world. If we want to have a web app (HTTP) we need to code servlets and add them into web.xml config, matching urls to Servlet Names. And within the Servlet we have coded, we need to call other Java code (the logic).
The container/app server takes care of the TCP/HTTP layers. Thread pools (which you can configure etc.).
Now in the Golang world. We just use the http package[1] for all that.
To listen to url:
http.Handle("/doSearch", &MySearch{"MySearch"})
Where MySearch is a struct which just needs to implement the interface:
func ServeHTTP( w http.ResponseWriter,r * http.Request)
Within this function you can put all the code which you will put in a java Servlet.
And to make this a service in your main package/program you will also do:
So these 3 pieces are the ones needed to have your own micro service or any web service running.
In our case, the similar functionality when moved resulted in lower memory usage and much higher stability (very less crashes, in the rare event of the service needing memory, which OS doesn't have. So the OS will kill that service anyhow - tech independent. We check using dmesg | grep <program name>)
Another benefit of this move, from our experience is getting rid of that webapp folder in any Java Servlet container. You will often end up plugging along multiple smaller apps, alongside your main one. And all reside in the same process.
That's not ample segregation, in our use. Its better you have different processes. So even if one dies, the others are independent.
This is also easier to manage. Deploy new ones - restarting just the ones changed.
Now we all know hot loading (without restart) is offered in several techs including some Java containers. But in practice, there always is some silly reason for you to restart. And sometimes the reason is psychological :-), we are not convinced that there is some baggage until we restart.
So hope my brief experience share is of some use. All the best.
Edit: Just want to add You must review this package page, if you are considering it
aws_ls|10 years ago
In the Tomcat/Jetty/<any other Java app server> world. If we want to have a web app (HTTP) we need to code servlets and add them into web.xml config, matching urls to Servlet Names. And within the Servlet we have coded, we need to call other Java code (the logic).
The container/app server takes care of the TCP/HTTP layers. Thread pools (which you can configure etc.).
Now in the Golang world. We just use the http package[1] for all that.
To listen to url:
Where MySearch is a struct which just needs to implement the interface: Within this function you can put all the code which you will put in a java Servlet.And to make this a service in your main package/program you will also do:
So these 3 pieces are the ones needed to have your own micro service or any web service running.In our case, the similar functionality when moved resulted in lower memory usage and much higher stability (very less crashes, in the rare event of the service needing memory, which OS doesn't have. So the OS will kill that service anyhow - tech independent. We check using dmesg | grep <program name>)
Another benefit of this move, from our experience is getting rid of that webapp folder in any Java Servlet container. You will often end up plugging along multiple smaller apps, alongside your main one. And all reside in the same process.
That's not ample segregation, in our use. Its better you have different processes. So even if one dies, the others are independent.
This is also easier to manage. Deploy new ones - restarting just the ones changed.
Now we all know hot loading (without restart) is offered in several techs including some Java containers. But in practice, there always is some silly reason for you to restart. And sometimes the reason is psychological :-), we are not convinced that there is some baggage until we restart.
So hope my brief experience share is of some use. All the best.
Edit: Just want to add You must review this package page, if you are considering it
[1] https://golang.org/pkg/net/http/
Mick-Jogger|10 years ago