2017-05-16 4 views
0

In der JSON-Datei befinden sich etwa 100000 Datensätze. Ich versuche, alle von ihnen in mantle.product.Product entity zu schreiben.Importieren von 100000+ Datensätzen aus einem JSON - langsamer Treffer zu AT_ENTITY

Der Vorgang beginnt und bei etwa 35000 Datensätze beginnt es mit der Warnung "Langsamer Treffer zu AT_ENTITY: create: mantle.product.Product" zu verschlechtern. Dann hält es definitiv mit 'java.lang.OutOfMemoryError: GC Overhead Limit überschritten' Fehler. Dieses Verhalten ist auf meinem PC.

Alle Hinweise willkommen.

Dies ist der Code:

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() 
      } 
     }) 
    } 
} 

Antwort

0

Dies scheint gut zu funktionieren, so dass, wenn jemand ähnliche Probleme hat, kann es helfen.

  1. da, ich wurde mit MoquiDevConf, erstes, was das langsame-Hit Problem zu lösen, ist die für den Typen AT_ENTITY,
  2. nächstes, was zu entfernen, ist der BufferedReader nicht die effektivste Lösung, um die Daten zu lesen, ich nutzte den InputStream, um die json ArrayList zu initialisieren.

Dies ist das Ergebnis:

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) 
Verwandte Themen