跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Java] 250M 的 Java 程序,用 go 重构,只需要 8M

发表于

把之前的 java 程序,这周学了下 golang ,然后用 golang 重构了下,稳定运行之后内存占用 8M 。

前文:

果然吃内存,一个简单的 Java 程序就占用了 250M 内存

quarkus-graalvm 可以救 Java native 一命

程序功能如下:

  • 每 10 分钟抓取某个链接的数据
  • 抓取到的内容和 mysql 里面已有的内容作对比
  • 存在就更新,不存在就插入到 mysql 中
  • 每天早上 10 点发送一个企业微信通知
  • 提供一个 rest 接口,上面的功能,可以通过定时触发,也可以通过接口手动触发(保留为了调试和验证程序情况,稳定之后几乎不会调用)。
  • 使用了 gin + gorm + cron 库(因为之前的 java 程序用了 sprinboot, 所以 go 我也特地选了大的库来使用)。

这几天的结果如下:

java springboot: 250M

java (无框架):90M

java, quarkus + graalvm + native: 50M

python: 20M

go: 8-10M 。


本来想用下 rust, 发现如果不系统的学习,根本没发写出正常的程序,暂时放弃了。


go 在资源受限的情况下,确实表现很好。之前我是排斥学 go 的,这次做项目发现,也不是不能接受。我之前写 C 的,要啥啥没有,现在有了 go, 就是 c with gc ,而且库多(相比于 c )。而且交叉编译非常方便。

不过工作中暂时用不到 go ,玩完了。 我还是选择 kotlin

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.