Skip to content

Performance down when used in parallel #5

Closed

Description

@charphi

Hi,
I'm using your library in a parallel stream and I have some performance issues: the average duration of a command is longer in parallel than in sequential.

Here is an example :

List<String> cmds = IntStream.range(0, 10).mapToObj(i -> "echo " + i).collect(Collectors.toList());

ToLongFunction<String> timer = o -> {
	long start = System.currentTimeMillis();
	try (PowerShell ps = PowerShell.open()) {
		ps.executeCommands(o);
	} catch (Exception ex) {
		return -1;
	}
	return System.currentTimeMillis() - start;
};

System.out.println(cmds.stream().mapToLong(timer).average());
System.out.println(cmds.stream().parallel().mapToLong(timer).average());

The problem seems to come from the creation of the executor service in PowerShell#open().

A possible solution would be to put PowerShell in some kind of pool. Therefore, the ExecutorService should be injected instead of beeing creating directly.

Any idea how to solve this problem?

Activity

  1. charphi commented on Sep 12, 2018

    @charphi
    ContributorAuthor

    After some digging, I have found that ExecutorService is not the main problem.

    A small part of the slowness comes from PowerShell#open() and a big one comes from the first call to PowerShell#executeCommands(String[]). Subsequent calls are really cheaper.

  2. Tuupertunut commented on Sep 14, 2018

    @Tuupertunut
    Owner

    That sounds like something the PowerShell process or the Java process API does on the first command. Usually it's pretty cheap to just leave the PS session open if you need to use it multiple times. Feel free to report back if you find something new, but I'm not interested in further investigating this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions