multithreading - Is Java fork/join (divide and conquor) possible when inserting line-by-line into MongoDB from InputStream? -


The list I listed below that batch inserts into MongoDB This code takes a long time - approximately 10 million To include 20 million Mongo documents.

Code time consuming part - scanner. HasNextLine () - Next line () - Insert loop - Runs as time moves slowly in 20 seconds. It becomes clear between the slow job, I pay attention. (The answer on this forum indicates that the Mongo insert can be batch or regular costly, binary format, due to the conversion of json into bson.)

I want to speed up the process . I would like to process this work in parallel to many cores. Can I use it for a fork / join? I would ask because I could not see a way of how to apply a split and how to get strategies in this code case, while with its loop on the input stream.

Another possibility is using ThreadPoolExecutor to use an executable best? What would an executor deliver to work on the core?

code:

  scanner line scanner = new scanner (inputstream, encoding); (LineScan.hasNextLine () {// to insert the list of DBObjects as a batch to batch // batch here, the object count has reached the limit.} While  

Similar codes are used by a ThreadPoolExecutor (See

more):

  ExecutorService Executor = Executors.newCachedThreadPool (); Iterator & lt; Long & Gt; i = getUserIDs (); while (i.hasNext ()) {last long l = i.next (); Runnable function = new runnable () {public zero run ({someObject.doSomething (l); anotheObject DoSomething (L);}} executor.submit (task);} executor.shutdown ();  

Any approach at which technique will accelerate this loop and insert in advance will be greatly appreciated very much.

You should consider the bulk write operation in 2.12 driver: Also, disabling indexes during insertion will also help in

.

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -