【问题标题】:High CPU usage on PI on kaa client startkaa 客户端启动时 PI 上的高 CPU 使用率
【发布时间】:2017-03-08 08:06:41
【问题描述】:

当我在树莓派上启动 KAA 客户端 SDK (JAVA) 时,CPU 使用率会飙升至 100%。一旦我终止进程,CPU 使用率就会恢复正常

下面是用于启动 kaa 的代码 sn-p,我在树莓派上启动 kaa 客户端

public class NotificationSystemTestApp {

    private static final Logger LOG = LoggerFactory.getLogger(NotificationSystemTestApp.class);

    public static void main(String[] args) throws InterruptedException {
        /*System.out.println(encryptString("abcd", "12332sd1133sdssd45"));
        return;*/
        new NotificationSystemTestApp().launch();
    }

    private void launch() throws InterruptedException {
        // Create client for Kaa SDK

        final KaaClient kaaClient;
        DesktopKaaPlatformContext desktopKaaPlatformContext = new DesktopKaaPlatformContext();
        final CountDownLatch startupLatch = new CountDownLatch(1);
        kaaClient = Kaa.newClient(desktopKaaPlatformContext, new SimpleKaaClientStateListener() {
            @Override
            public void onStarted() {
                LOG.info("--= Kaa client started =--");
                startupLatch.countDown();
            }

            @Override
            public void onStopped() {
                LOG.info("--= Kaa client stopped =--");
            }
        }, true);

        kaaClient.setProfileContainer(new ProfileContainer() {
            public ClientProfile getProfile() {
                return new ClientProfile() {{
                    setClientProfileInfo(new ProfileInfo() {{
                        setRidlrId("R_00001");
                        setStationName("Mumbai");
                        setEquipmentId("EQ0006");
                        setStationId("5");
                    }});
                }};
            }
        });
        // Registering listener for topic updates

        kaaClient.start();
        startupLatch.await();

        kaaClient.addTopicListListener(new NotificationTopicListListener() {
            public void onListUpdated(List<Topic> topicList) {
                System.out.println("Topic list updated!");
                for (Topic topic : topicList) {
                    LOG.info("Received topic with id {} and name {}", topic.getId(), topic.getName());
                }
            }
        });

        final ScanInfo scanInfo = new ScanInfo() {{
            setDestinationId("12");
            setSourceId("3");
            setEquipmentId("R_00001");
            setScanTime(System.currentTimeMillis() / 1000);
            setEvent("ENTRY");
            setTransactionId(UUID.randomUUID().toString());
        }};

        kaaClient.attachEndpoint(new EndpointAccessToken("1234"), new OnAttachEndpointOperationCallback() {
            @Override
            public void onAttach(SyncResponseResultType result, EndpointKeyHash resultContext) {

            }
        });
        kaaClient.attachUser("user1", "1234", new UserAttachCallback() {
            public void onAttachResult(UserAttachResponse response) {
                System.out.println("Attach User Success - " + response.getResult());
            }
        });


        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            LOG.error("FATA", e);
        }


        LOG.debug("End Point key hash - " + kaaClient.getEndpointKeyHash());
        while (true) {
            kaaClient.addLogRecord(new LoggerSchema() {{
                setData("");
                setMessageType("");
            }});
            Thread.sleep(10);
        }
    }
}

谢谢, 里兹万

【问题讨论】:

    标签: kaa


    【解决方案1】:

    如我所见,您使用不断添加日志记录来上传到 Kaa 服务器。延迟仅为 10 毫秒,这对于您运行应用程序的 Raspberry PI 系统来说可能太短了。

    根据配置,Kaa 客户端可能会为每个日志记录增加相当大的处理开销,并在其他 Java 线程中进行处理,从而导致 CPU 不断地旋转添加和处理新记录。

    尝试增加“while (true)”循环中的延迟,并使用不同的日志上传设置检查 CPU 使用率。

    如果这些信息不足以让您解决问题,请添加来自 Kaa 客户端和 Kaa 服务器的日志以供调查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-14
      • 1970-01-01
      相关资源
      最近更新 更多