What happens when you do a FilePath.readToString() on a Master/Slave setup?

12 views
Skip to first unread message

Daniel Anechitoaie

unread,
Apr 5, 2019, 4:11:27 AM4/5/19
to Jenkins Developers
What happens when you do a FilePath.readToString() on a Master/Slave setup?
Will the master read the contents of the file from the salve and process the contents locally?

Is it better to do a FilePath.act() so that the processing will happen on the slave and then the master will just get the results?

Jesse Glick

unread,
Apr 5, 2019, 9:17:49 AM4/5/19
to Jenkins Dev
On Fri, Apr 5, 2019 at 4:11 AM Daniel Anechitoaie <danie...@gmail.com> wrote:
> What happens when you do a FilePath.readToString() on a Master/Slave setup?
> Will the master read the contents of the file from the salve and process the contents locally?

I am not sure what you mean by “process” in this context. The master
will send a request to the agent to load the file into a string, and
the agent sends back a response with that string.

Reading between the lines a bit, I think you are asking something like
this: suppose the agent workspace contains some possibly big file and
you only need a little bit of information from it. In that case it is
a bad idea to write

FilePath file = workspace.child("all-results.xml");
String xml = file.readtoString(); // slow!
int count = countNumberOfResults(xml);

The better code would be:

FilePath file = workspace.child("all-results.xml");
int count = file.act(new CountNumberOfResults());
// …
private static final class CountNumberOfResults extends
MasterToSlaveFileCallable<Integer> {…}

so that the response on the Remoting channel just contains the one
integer and not the complete file contents.

Daniel Anechitoaie

unread,
Apr 5, 2019, 9:28:22 AM4/5/19
to Jenkins Developers
Your "read between the lines" was spot on. Sorry for not being more clear I was not sure how to explain my train of thoughts.
It's clear now.
Thank you.
Reply all
Reply to author
Forward
0 new messages