当我在覆盆子PI上启动KAA客户端SDK(JAVA)时,CPU使用率最高可达100%。一旦我终止进程,CPU使用率就会恢复正常
下面是用于启动kaa的代码片段,我将在覆盆子pi上启动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);
}
}
}
谢谢, RIZWAN
答案 0 :(得分:0)
正如我所见,您使用不断添加的日志记录来上传到Kaa服务器。延迟只有10毫秒,对于运行应用程序的Raspberry PI系统来说可能太短了。
根据配置的不同,Kaa Client可能会为每个日志记录增加相当大的处理开销,并在其他Java线程中进行处理,从而导致CPU不断旋转添加和处理新记录。
尝试增加&#39; while(true)&#39;循环并使用不同的日志上载设置检查CPU使用情况。
如果此信息不足以解决问题,请从Kaa客户端和Kaa服务器添加日志进行调查。