2017-03-08 128 views
0

當我在樹莓派PI上啓動KAA客戶機SDK(JAVA)時,CPU使用率高達100%。只要我殺的過程中CPU佔用率降回正常在kaa客戶機上啓動PI時CPU佔用率高

下面是一個使用的地方開始我開始了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的KAA的代碼片段

回答

0

正如我所看到的,您使用不斷添加的日誌記錄上傳到Kaa服務器。延遲僅爲10毫秒,對於正在運行應用程序的Raspberry PI系統可能太短。

根據配置的不同,Kaa Client可能會爲每個日誌記錄添加相當大的處理開銷,並在其他Java線程中處理,從而導致CPU不斷地添加和處理新記錄。

嘗試增加'while(true)'循環中的延遲並檢查CPU使用情況並使用不同的日誌上傳設置。

如果這些信息不足以解決您的問題,請從Kaa客戶端和Kaa服務器上添加日誌進行調查。