Java 中 CPU 利用率太低

发布于 2024-07-10 19:49:13 字数 442 浏览 9 评论 0原文

嘿 stackoverflow 社区!

我遇到一个问题,一个高度复杂的算法程序使用的 CPU 利用率太低:在 3% 到 4% 之间。 返回结果需要很长时间,我相信只是工作不够努力。

你们中的任何一位天才是否知道为什么会发生这种情况 - 如果有的话,我希望 100% 利用率。 另一个细节是该程序将插入到 sqlite3 数据库中,因此,是的,我相信有很多通过 sqlite3jdbc 库进行的 JNI 调用。 (请注意,我想早些时候使用PreparedQuery 批处理推迟这些插入,但这导致了主要的内存问题 - 有大量数据)。

提前致谢

更新:已修复。 是的,我只是在犯傻,但我没想到 sqlite 会启动一个新事务并产生如此大的开销。

我现在使用PreparedStatement 并在插入之前排队32768 个条目——对我来说这似乎是一个足够好的数字。

Hey stackoverflow community!

I'm having an issue where a highly involved algorithmic program is using TOO LITTLE cpu utilization: somewhere between 3 and 4%. It is taking very long to return results, and I believe it's just not working hard enough.

Do any of you geniuses have any ideas why this would occur - if anything I would expect 100% utilization. One additional detail is that the program makes inserts into a sqlite3 database, and thus yes, there are a lot of JNI calls via the sqlite3jdbc library I believe. (Note that I wanted to defer these inserts with a PreparedQuery batch earlier, but this caused major memory problems - there's a lot of data).

Thanks in advance

UPDATE: Fixed. Yeah, I was just being a doofus, but I didn't expect that sqlite would start a new transaction and do so much overhead.

I now use a PreparedStatement and queue 32768 entries before insert - seemed like a good enough number to me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼眸 2024-07-17 19:49:13

如果有 IV 型、100% Java 版本可用,我绝不会建议某人使用带有 JNI 的 JDBC 驱动程序。 Google 发现了这个

除此之外,如果没有更多信息,我无法透露任何信息。 应用程序和数据库是否在同一硬件上运行?

INSERT 有何“密集”之处?

我建议分析并获取一些真实数据,而不是猜测。 基于信仰的计算对我来说从来不起作用。

I would never recommend that someone use a JDBC driver with JNI if a type IV, 100% Java version is available. Google found this one.

With that aside, I can't tell anything without more info. Are the app and the database running on the same hardware?

What is so "intensive" about INSERTs?

I'd recommend profiling and getting some real data rather than guessing. Faith-based computing never works for me.

┼── 2024-07-17 19:49:13

显然,数据库调用导致了延迟。 不是可以选择创建较小的批次并测试是否有帮助吗? 也许您也可以并行化该算法,以便在某个地方有一个队列来获取结果,而另一个线程则清理该队列?

编辑:

还有一些其他问题领域:

  • 数据库优化(模型)
  • 数据库服务器配置
  • 磁盘速度

所有这些因素都应该考虑在内

Obviously the database calls are causing delays. Isn't it an option to create smaller batches and test if that helps?? Maybe you could parallelize the algorithm as well to have a queue somewhere taking results and another thread cleaning out that queue?

edit:

There are also some other problem areas:

  • Database optimalization (model)
  • Database server configuration
  • Disk speed

All these factors should be taken into account

穿透光 2024-07-17 19:49:13

如果您正在写入大量数据,那么听起来您可能会受到磁盘限制。 查看计算机上的磁盘 io 统计信息,如果这确实是瓶颈,请查找具有更好 io 的硬件,或者找出如何减少写入。

If you're writing a lot of data, then it sounds like you may be disk bound. Take a look at your disk io stats on the machine, and if that's actually the bottleneck, either find hardware with better io, or figure out how to do less writes.

把昨日还给我 2024-07-17 19:49:13

磁盘正在减慢您的应用程序的速度。 INSERTS使用磁盘,磁盘速度慢,操作系统需要等待写入操作完成。

不能使用 2 个线程,一个用于算法,另一个用于插入吗?
如果您只进行插入,您也可以将其写入文本文件,并在稍后执行它们

The disk is slowing down your app. INSERTS use the disk, disk is slow, and the OS needs to wait for the write operations to finish.

Can't you use 2 threads, one for the algorithm, and another for the inserts?
If you only make inserts, you may also write then to a text file, and execute them at a later time

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文