2017-05-16 6 views
0

JSON 파일에는 약 100000 개의 레코드가 있습니다. 저는 맨틀에 모든 것을 쓰려고합니다. 제품. 제품 실체.JSON에서 100000 개가 넘는 레코드 가져 오기 - AT_ENTITY로 천천히 이동

절차가 시작되고 약 35000 개의 레코드에서 'AT_ENTITY에 천천히 충돌합니다. 생성 : mantle.product.Product'으로 악화되기 시작합니다. 그런 다음 'java.lang.OutOfMemoryError : GC 오버 헤드 한도 초과'오류로 확실히 중단됩니다. 이 동작은 내 PC에서 발생합니다.

힌트를 환영합니다.

코드입니다 :

void processJson2(String filePath) { 
    //def json = new JsonSlurper().parseText(new BufferedReader(new InputStreamReader(this.getFileIO().openStream(), "UTF-8"))) 

    //will initialize class manually 
    def docReadReference = this.executionContext.resource.getLocationReference(filePath) 

    if (docReadReference.isFile()) { 
     //inputstream 
     InputStream inputFile = docReadReference.openStream() 
     TransactionFacade trxFacade = this.executionContext.getTransaction() 

     this.executionContext.artifactExecution.disableTarpit() 
     this.executionContext.artifactExecution.disableEntityEca() 
     this.executionContext.artifactExecution.disableAuthz() 

     trxFacade.runRequireNew(50000, "Error loading entity JSON data", { 

      try { 
       logMachine.info("Opening file ${docReadReference.isFile()}") 

       JsonSlurper slurper = new JsonSlurper().setType(JsonParserType.CHARACTER_SOURCE) 
       def json = slurper.parse(new BufferedReader(new InputStreamReader(inputFile, "UTF-8"))) 

       //writer 
       Long counter = 1 

       json.each { 
        this.executionContext.service.sync().name("create", "mantle.product.Product").parameters([productId: it.sourceFileReference]).call() 

        //display thousands 
        if (counter % 1000 == 0) { 
         logMachine.info("JSON rows processed ${counter} > ${it.sourceFileReference}") 
        } 

        //move counter 
        counter += 1 
       } 

       //log 
       logMachine.info("File processed.") 

      } catch (Throwable t) { 
       trxFacade.rollback("Error while processing JSON", t); 

       //log as warning 
       logMachine.warn("Incorrectly handled JSON parsing ${t.message}.") 
      } finally { 
       if (trxFacade.isTransactionInPlace()) trxFacade.commit(); 

       inputFile.close() 

       this.executionContext.artifactExecution.enableTarpit() 
       this.executionContext.artifactExecution.enableEntityEca() 
       this.executionContext.artifactExecution.enableAuthz() 
      } 
     }) 
    } 
} 

답변

0

이 잘 작동하는 것 같다, 그래서 누군가가 비슷한 문제가있는 경우, 그것은 도움이 될 수 있습니다. 내가 MoquiDevConf를 사용하고, 이후

  1. 가, 느린 충돌 문제를 해결하기 위해 제일 먼저 입력 AT_ENTITY에 대한
  2. 다음 일을을 제거하는 것입니다,을, BufferedReader는 데이터를 읽을 수있는 가장 효과적인 해결책은 내가 아니다 json ArrayList를 초기화하기 위해 InputStream을 사용했다.

    InputStream inputFile = docReadReference.openStream() 
         TransactionFacade trxFacade = this.executionContext.getTransaction() 
    
    
         JsonSlurper slurper = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY) 
         //ArrayList<Object> json = slurper.parse(new BufferedReader(new InputStreamReader(inputFile, "UTF-8"))) 
         ArrayList<Object> json = slurper.parse(inputFile) 
    
    :

이는 결과입니다