JavaFX 8 QuantumRenderer CPU使用率很高 [英] JavaFX 8 QuantumRenderer high CPU usage

查看:572
本文介绍了JavaFX 8 QuantumRenderer CPU使用率很高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaFX APP,其中包含两个列表视图,显示从我的服务器收到的传入客户订单(使用自定义cellfactory)。我还有一些tableview显示来自Postgres数据库的信息(这些信息分布在tabpane中的几个选项卡中)。
用户必须接受订单(通过点击它),并在文本框中输入一些信息。

I have a JavaFX APP containing two listviews displaying incoming customer orders (using a custom cellfactory) received from my server. I also have a few tableview displaying information from a Postgres database (this are spread across a few tabs inside a tabpane). The user has to take an order (by clicking on it), and enter a few information inside textboxes.

应用程序最初编写为使用Java7部署。我没有任何问题。
但最近我决定改用Java8。我修改了我的代码以使用lambdas并在应用程序中添加了一些额外内容:

The application was initially written an deployed using Java7. I had no problem whatsoever. But recently I decided to switch to Java8. I modified my code to use lambdas and added a few extras stuff to the app:


  • 每分钟检查和显示订单状态的时间表,在文本流中;

  • 修改了customcellfactory类以使用外部CSS,使用setId而不是setStyle;

  • ...

现在,应用程序运行正常,但是在运行2-3小时后它变得迟缓。由于我很难模拟探查器内部的行为,我使用jstack, top -H ,并匹配 pid with nid 了解发生了什么。

Now, the application is running fine but, after 2-3 hours of uptime it becomes sluggish. Since is hard for me simulate the behavior inside a profiler I used jstack, top -H, and matching pid with nid to find out what is happening.

这样我发现罪魁祸首是具有95 +%CPU使用率的QuantumRenderer

This way I found out that the culprit was QuantumRenderer with 95+% CPU usage:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
30300 utilizat+  20   0 5801608 527412  39696 S  95,1  6,5  60:57.34 java

"QuantumRenderer-0" #9 daemon prio=5 os_prio=0 tid=0x00007f4f182bb800 nid=0x765c runnable [0x00007f4eeb2a1000]
   java.lang.Thread.State: RUNNABLE
    at com.sun.prism.es2.X11GLDrawable.nSwapBuffers(Native Method)
    at com.sun.prism.es2.X11GLDrawable.swapBuffers(X11GLDrawable.java:50)
    at com.sun.prism.es2.ES2SwapChain.present(ES2SwapChain.java:186)
    at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:107)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
    at java.lang.Thread.run(Thread.java:745)

运行应用程序的机器使用的是润滑剂的64位版本。

The machine running the application is using a 64Bit version of Lubuntu.

我无法弄清楚我应该在哪里找出问题所在...

I can't figure out where should I look to find out what is the problem...

推荐答案

看来你的渲染器正在使用X11管道(Java2D?),这可能是高CPU使用率(软件加速)的原因。您的显卡是否支持硬件加速?

It seems your renderer is using the X11 pipeline (Java2D?) which could be the cause of high CPU usage (software acceleration). Does your graphics card supports hardware acceleration?

如果您的显卡支持您可能需要的硬件加速,请尝试使用 -Dprism.verbose = true 获取更多信息尝试使用 -Dprism.forceGPU = true 强制它,还尝试使用
-Dprism启用OpenGL管道来提高Java2D性能。 order = es2,es1,sw,j2d
(你也可以尝试旧的Java2D标志
-Dsun.java2d.opengl = true
但我认为这不会影响棱镜。)

Try getting more information with -Dprism.verbose=true if your graphics card does support hardware acceleration you might want to try to force it with -Dprism.forceGPU=true, also try enabling the OpenGL pipeline to increase Java2D performance with -Dprism.order=es2,es1,sw,j2d (you could also try with the old Java2D flag -Dsun.java2d.opengl=true but I think that won't affect prism).

我还建议你看一下OpenJFX 性能提示和技巧清单我看到节点中的CPU使用率很高,但是使用< a href =https://docs.oracle.com/javase/8/javafx/api/javafx/scene/Node.html#setCache-boolean-\"rel =nofollow noreferrer> Node.setCache(true)及其 CacheHints (其缺点是使用更多内存)。

I would also recommend taking a look at the OpenJFX performance tips and tricks checklist I've seen high CPU usage in nodes that was somewhat fixed with the usage of Node.setCache(true) and its CacheHints when using any kind of animation (with the downside that this uses more memory).

另外,请看一下如何从工作线程更新UI。在FX UI线程中进行最小化工作并正确地从您的工作人员更新它是非常重要的,并且只在必要时,请查看另一个问题以了解有关 javafx.concurrent.Task 类的更多信息以及从工作线程更新UI的正确用法。

Also, take a look at how you are updating your UI from your worker threads. It's important to do minimum work in the FX UI Thread and update it from your workers correctly and only when necessary, take a look at this other question to learn more about the javafx.concurrent.Task class and its correct usage to update the UI from worker threads.

这看起来更像是一个软件加速问题,而Dprism.verbose应该让你知道更多,但遵循其他建议永远不会伤害!希望这会有所帮助!

This seems much more like a software acceleration issue and Dprism.verbose should let you know more but following the other suggestions never hurts! Hope this helps!

这篇关于JavaFX 8 QuantumRenderer CPU使用率很高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆