kandi background
Explore Kits

AlgoDS | Implementation of Algorithms and Data Structures, Problems and Solutions | Learning library

 by   sherxon Java Version: Current License: MIT

 by   sherxon Java Version: Current License: MIT

Download this library from

kandi X-RAY | AlgoDS Summary

AlgoDS is a Java library typically used in Tutorial, Learning, Example Codes applications. AlgoDS has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. However AlgoDS build file is not available. You can download it from GitHub.
Implementation of Algorithms and Data Structures, Problems and Solutions
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • AlgoDS has a medium active ecosystem.
  • It has 3243 star(s) with 632 fork(s). There are 169 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 4 open issues and 8 have been closed. On average issues are closed in 4 days. There are 15 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of AlgoDS is current.
AlgoDS Support
Best in #Learning
Average in #Learning
AlgoDS Support
Best in #Learning
Average in #Learning

quality kandi Quality

  • AlgoDS has 0 bugs and 0 code smells.
AlgoDS Quality
Best in #Learning
Average in #Learning
AlgoDS Quality
Best in #Learning
Average in #Learning

securitySecurity

  • AlgoDS has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • AlgoDS code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
AlgoDS Security
Best in #Learning
Average in #Learning
AlgoDS Security
Best in #Learning
Average in #Learning

license License

  • AlgoDS is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
AlgoDS License
Best in #Learning
Average in #Learning
AlgoDS License
Best in #Learning
Average in #Learning

buildReuse

  • AlgoDS releases are not available. You will need to build from source code and install.
  • AlgoDS has no build file. You will be need to create the build yourself to build the component from source.
  • AlgoDS saves you 11001 person hours of effort in developing the same functionality from scratch.
  • It has 22300 lines of code, 1576 functions and 621 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
AlgoDS Reuse
Best in #Learning
Average in #Learning
AlgoDS Reuse
Best in #Learning
Average in #Learning
Top functions reviewed by kandi - BETA

kandi has reviewed AlgoDS and discovered the below as its top functions. This is intended to give you an instant insight into AlgoDS implemented functionality, and help decide if they suit your requirements.

  • Search for the last played file
  • Find the least interval in tasks
  • Calculates the order of the numbers in the array with the lowest sign .
  • returns the zigag - level order in the tree
  • Split a list into partitions .
  • Merge accounts .
  • Checks whether the given graph is bipartiteite .
  • Returns true if the tree is a leaf .
  • Determine the price for the cheapest price .
  • Calculates the knot hash of a string .

AlgoDS Key Features

Implementation of Algorithms and Data Structures, Problems and Solutions

ForkJoinPool size increasing dynamically?

copy iconCopydownload iconDownload
                        if ((wt = q.owner) != null &&
                            ((ts = wt.getState()) == Thread.State.BLOCKED ||
                             ts == Thread.State.WAITING))
                            ++bc;            // worker is blocking
            if (Thread.currentThread() instanceof ForkJoinWorkerThread)
                ForkJoinPool.helpAsyncBlocker(defaultExecutor(), q);
-----------------------
                        if ((wt = q.owner) != null &&
                            ((ts = wt.getState()) == Thread.State.BLOCKED ||
                             ts == Thread.State.WAITING))
                            ++bc;            // worker is blocking
            if (Thread.currentThread() instanceof ForkJoinWorkerThread)
                ForkJoinPool.helpAsyncBlocker(defaultExecutor(), q);

Community Discussions

Trending Discussions on AlgoDS
  • ForkJoinPool size increasing dynamically?
Trending Discussions on AlgoDS

QUESTION

ForkJoinPool size increasing dynamically?

Asked 2021-May-06 at 14:20

Related: CompletableFuture on ParallelStream gets batched and runs slower than sequential stream?

I'm doing some research on different ways of parallelizing network calls through parallelStream and CompletableFutures. As such, I have come across this situation where the ForkJoinPool.commonPool(), which is used by java's parallelStream, is dynamically growing in size, from ~ #Cores, to Max value of 64.

Java details: $ java -version

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)

Code that shows such behavior is below (Full executable code here)


    public static int loops = 100;
    private static long sleepTimeMs = 1000;
    private static ExecutorService customPool = Executors.newFixedThreadPool(loops);




    // this method shows dynamic increase in pool size
    public static void m1() {
        Instant start = Instant.now();
        LongSummaryStatistics stats = LongStream.range(0, loops).boxed()
                .parallel()
                .map(number -> CompletableFuture.supplyAsync(
                        () -> DummyProcess.slowNetworkCall(number), customPool))
                .map(CompletableFuture::join)
                .mapToLong(Long::longValue)
                .summaryStatistics();

    }

    // this method shows static pool size
    public static void m2() {
        Instant start = Instant.now();
        LongSummaryStatistics stats = LongStream.range(0, loops)
                .parallel()
                .map(DummyProcess::slowNetworkCall) // in this call, parallelism/poolsize stays constant 11
                .summaryStatistics();
    }


    public static Long slowNetworkCall(Long i) {
        Instant start = Instant.now();
        // starts with 11 (#cores in my laptop = 12), goes upto 64
        log.info(" {} going to sleep. poolsize: {}", i, ForkJoinPool.commonPool().getPoolSize());
        try {
            TimeUnit.MILLISECONDS.sleep(sleepTimeMs);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info(" {} woke up..", i);
        return Duration.between(start, Instant.now()).toMillis();
    }

Sample output:

16:07:17.443 [pool-2-thread-7] INFO  generalworks.parallelism.DummyProcess -  44 going to sleep. poolsize: 11
16:07:17.443 [pool-2-thread-9] INFO  generalworks.parallelism.DummyProcess -  7 going to sleep. poolsize: 12
16:07:17.443 [pool-2-thread-4] INFO  generalworks.parallelism.DummyProcess -  6 going to sleep. poolsize: 12
16:07:17.444 [pool-2-thread-13] INFO  generalworks.parallelism.DummyProcess -  82 going to sleep. poolsize: 13
16:07:17.444 [pool-2-thread-14] INFO  generalworks.parallelism.DummyProcess -  26 going to sleep. poolsize: 14
16:07:17.444 [pool-2-thread-15] INFO  generalworks.parallelism.DummyProcess -  96 going to sleep. poolsize: 15
16:07:17.445 [pool-2-thread-16] INFO  generalworks.parallelism.DummyProcess -  78 going to sleep. poolsize: 16
.
.
16:07:18.460 [pool-2-thread-79] INFO  generalworks.parallelism.DummyProcess -  2 going to sleep. poolsize: 64
16:07:18.460 [pool-2-thread-71] INFO  generalworks.parallelism.DummyProcess -  36 going to sleep. poolsize: 64
16:07:18.460 [pool-2-thread-74] INFO  generalworks.parallelism.DummyProcess -  77 going to sleep. poolsize: 64
16:07:18.461 [pool-2-thread-83] INFO  generalworks.parallelism.DummyProcess -  86 going to sleep. poolsize: 64

I understand that the number of Threads in a commonpool, i.e, it parallelism is based upon max number of available cores, so since my laptop has 12 cores, i get a parallelism of 11 to start with. But I do not understand why it keeps climbing in one method, but in the other one, it's size keeps constants

ANSWER

Answered 2021-May-06 at 12:53

I believe your answer is here (ForkJoinPool implementation):

                        if ((wt = q.owner) != null &&
                            ((ts = wt.getState()) == Thread.State.BLOCKED ||
                             ts == Thread.State.WAITING))
                            ++bc;            // worker is blocking

In one version of your code, you block on Thread.sleep, which puts the thread into the TIMED_WAITING state, while in the other you block on CompletableFuture.join(), which puts it into the WAITING state. The implementation distinguishes between these and exhibits the different behaviors you have observed.

There is also special-cased code inside CompletableFuture that makes it cooperate with the ForkJoinPool in order to prevent starvation while waiting for the result:

            if (Thread.currentThread() instanceof ForkJoinWorkerThread)
                ForkJoinPool.helpAsyncBlocker(defaultExecutor(), q);

A conclusion relevant to the reason why you're testing this in the first place: Thread.sleep() does not properly simulate a long network call. If you did an actual one, or some other blocking operation, it would compensate by extending the pool.

Source https://stackoverflow.com/questions/67416858

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install AlgoDS

You can download it from GitHub.
You can use AlgoDS like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the AlgoDS component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

Here are questions divided by difficulty level:.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.