将Java应用程序移植到Go语言 – 有什么建议吗?

huangapple go评论113阅读模式
英文:

Porting Java app to Go - any advice?

问题

我们想用Go重写kodingen.com的后端,目前是用Java编写的,作为守护进程运行,使用jsvc

我从未接触过C语言,只有Java的经验,所以我不知道是否应该开始学习C语言。

然而,任务非常简单:

  • 从MySQL数据库中读取shell命令
  • 并行排队和执行这些命令
  • 将每个shell的输出保存到数据库中

就是这样。所以这些简单的要求让我对能够开始使用这门优秀的语言充满了希望。

你会给什么建议?C语言还是更好?

英文:

We want to rewrite kodingen.com backend with Go which currently is
Java, running as daemon using jsvc.

I have never touched any C in my life, am only experienced in Java so I
don't know if this is something that I should even start.

However, task is pretty simple

  • read shell commands from mysql database
  • queue and execute them in parallel
  • save each shell output to the database

that's it. So these simple requirements gives me hope that I can start
using this wonderful language.

What would you advise? Is C still better ?

答案1

得分: 3

我非常喜欢Go,并且为该项目做出了贡献。然而,在决定使用Go之前,我认为你应该考虑一些事情。

  • Go仍然是一门不稳定的语言。它的语法、特性和包都可能发生变化。如果选择使用它,请确保你能跟上这些变化。
  • Go的垃圾回收机制仍然不够成熟。你的内存使用应该比1.2GB好,但可能不会接近C语言的水平。
  • Go没有对MySQL(或任何其他数据库)提供核心支持。有几个非官方的MySQL包项目。最近更新的是GoMySQLGo-MySQL-Client-Library。我不知道它们的完整性和稳定性如何。

至于队列和并行执行,我认为Go将能够很好地完成这些任务。你可能会使用exec包来执行和并行化处理,使用goroutines。

英文:

I like Go a lot and have made contributions to the project. However, I think you ought to consider a few things about Go before settling on it for sure.

  • Go is still an unstable language. Its syntax, features, and packages are all subject to change. Make sure you're ready to keep up with this if you choose to use it.
  • Go's garbage collection is still immature. Your memory usage should be better than 1.2 GB, but it probably won't get you near C levels.
  • There's no core support for MySQL (or any other database). There are several unofficial MySQL package projects. The most recently updated ones are
    GoMySQL and Go-MySQL-Client-Library. I don't know anything about how complete or stable they are.

As for queuing and executing in parallel, I think that's something Go will be able to do pretty well. You'll probably use the exec package to execute and parallelize with goroutines.

答案2

得分: 1

我同意 @Chickencha

目前我没有更新我的 1: http://github.com/chbfiv/libmysqlgo "libmysqlgo" 项目的计划。欢迎贡献,但是我现在太忙了。我建议使用更活跃的mysql go项目。

英文:

I agree with @Chickencha

At this point I have no plans to update my 1: http://github.com/chbfiv/libmysqlgo "libmysqlgo" project. Contributions are welcome, but I'm too busy atm. I would recommend using more active mysql go projects.

答案3

得分: 1

从Go语言FAQ中:

Go项目的构想是为了更容易编写类似Google内部使用的服务器和其他软件,但是实现还不够成熟,还不能用于大规模的生产环境。

据我所知,Go的垃圾回收器和调度器还没有准备好。
而且它的编译器还不够优化,无论如何,C编译器已经改进了20年。
如果你想在生产环境中使用它,最好等待Go变得足够成熟。

但这并不意味着Go不是一个好的学习语言。
实际上,我很高兴地使用它来开发一些有用的工具。

编辑:在切换到另一种语言之前,不妨先尝试一些即将推出的JDK 7的实验。垃圾回收方面有一些改进。
你可以检查一下在你的情况下内存管理是否更好。

英文:

From the go langugage FAQ:

> The Go project was conceived to make
> it easier to write the kind of servers
> and other software Google uses
> internally, but the implementation
> isn't quite mature enough yet for
> large-scale production use.

As I know, Go's garbage collector and scheduler is not ready yet.
And its compiler is not optimized enough, anyway, C compiler has been improved for 20 years.
If you want to use it in a production site, waiting for Go to be mature enough is better.

But that does not mean Go is not a good language to learn.
Actually, I'm happily using it to develop some useful utilities.

EDIT: Before you switch to another language, how about making some experiments with the forthcoming JDK 7. There are some improvements in the garbage collection.
You can check is the memory management better in your case.

答案4

得分: 1

我认为随着最近添加的panic/recover功能,Go语言开始成为一个可行的网站后端选项。我一直在使用Go运行一些简单的Facebook应用程序,但是当出现诸如地图键错误或空指针异常等问题时,整个应用程序都会崩溃,这让人沮丧。有了panic/recover,就可以管理崩溃了。

关于你的要求-对于mysql和shell命令来说应该没问题。但是要准备好修补一些库 将Java应用程序移植到Go语言 – 有什么建议吗?

英文:

I think with the recent addition of panic/recover, Go is starting to become a viable option for website backends. I've been running a couple simple facebook apps using Go, but it's frustrating having the entire app go down for something like a map key error, or a null pointer exception. With panic/recover, it'll be possible to manage crashes.

About your requirements - it should be fine for mysql and shell commands. But be prepared to patch some libraries 将Java应用程序移植到Go语言 – 有什么建议吗?

huangapple
  • 本文由 发表于 2010年4月12日 07:52:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/2619189.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定