Git Product home page Git Product logo

fork-join-study's Introduction

Fork / Join Study

Study Fork / Join with a few examples.

Word Count

The code shows the performance gain via running word count using fork join pool.

Single thread,Fork/Join
1337,242
714,255
693,467
692,238
693,245
700,244
689,241
691,242
685,243
691,248

To run wordcount.WordCounter, set program arguments as wordcount me 10.

Reference: https://www.oracle.com/technical-resources/articles/java/fork-join.html

Web Crawler

The code shows how to do web crawler using fork join or fixed thread pool pattern. It also shows the performance gain of using fork join in the specific case.

-----------------
Fixed thread pool
-----------------
Visiting 100 links takes 2755 ms
Visiting 200 links takes 4833 ms
Visiting 300 links takes 6761 ms
Visiting 400 links takes 11252 ms
Visiting 500 links takes 12970 ms
Visiting 600 links takes 16050 ms
Visiting 700 links takes 17360 ms
Visiting 800 links takes 19572 ms
Visiting 800 links takes 19599 ms
Visiting 900 links takes 45158 ms
Visiting 1000 links takes 63665 ms

-----------------
Fork join pool
-----------------
Visiting 100 links takes 1340 ms
Visiting 200 links takes 2431 ms
Visiting 300 links takes 3357 ms
Visiting 400 links takes 4239 ms
Visiting 400 links takes 4239 ms
Visiting 500 links takes 5111 ms
Visiting 600 links takes 5967 ms
Visiting 700 links takes 7049 ms
Visiting 800 links takes 8044 ms
Visiting 800 links takes 8047 ms
Visiting 800 links takes 8049 ms
Visiting 900 links takes 9035 ms
Visiting 1000 links takes 10092 ms
Visiting 1000 links takes 10099 ms

Note that it shows duplicated logs such as

Visiting 1000 links takes 10092 ms
Visiting 1000 links takes 10099 ms

This is because there can be multiple threads hitting the size=1000 during a short period when no new link is added to the set.

Reference: https://www.infoworld.com/article/2078440/java-tip-when-to-use-forkjoinpool-vs-executorservice.htm

fork-join-study's People

Contributors

yiksanchan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.