Repository navigation
Conversation
Add a argument `max_parallel_num` for `tf.gfile.Glob`, which will setup a threadpool to parallelize the matching for mulitple pattern strings. It can bring nice performance improvement if `max_parallel_num` is set appropriately. Thanks for your review.
tf.gfile.Globtf.gfile.Glob
|
Since the matching happensinside C++ code, I'm afraid this PR does not do what it says it does. |
|
@mihaimaruseac Thanks for your reply! I also considered the issue you mentioned in fact. In the C++ implement of different BTW, I have obtained nice effect in my case that using pattern = ['hdfs://xxxx_1/*', 'hdfs://xxxx_2/', 'hdfs://xxxx_3/, 'hdfs://xxxx_4/', 'hdfs://xxxx_5/']
begin_time = int(time.time())
files = tf.gfile.Glob(pattern, max_parallel_num=5)
print('size: {}, used time: {} s'.format(len(files), int(time.time()) - begin_time))As the final size of The above is my reason for proposing this pr and there may be some incompleteness. I am looking forward to your valuable suggestions for improvement. |
Change max size of threadpool for parallel BFS of `GetMatchingPaths` to use more available resource.
|
This looks good to me now. Since it changes API, let's wait for API owners approval too |
fchollet
left a comment
There was a problem hiding this comment.
Maybe the choice of the number of threads to use should be automated, rather than specified by the user. Most users will not be aware of this argument. What do you think?
|
@fchollet Thanks for your review!
In fact I have implemented automatically using This is my reason for setting it as a configurable parameter and I would like to discuss further with you. |
|
@fchollet Could you please check this again? |
mihaimaruseac
left a comment
There was a problem hiding this comment.
Please don't forget about posting some benchmark results
|
|
||
| @tf_export("io.gfile.glob") | ||
| def get_matching_files_v2(pattern): | ||
| def get_matching_files_v2(pattern, num_threads=1): |
There was a problem hiding this comment.
I thought we were going to automatically determine the best number of threads if user didn't supply any.
There was a problem hiding this comment.
Sorry that I reopened this conversation. As for the default values of num_threads, I think we may need to have more discuss.
I have made benchmarks on a multi-core (80 threads) server and the default value of num_threads (len(patterns)) can produce a quite positive optimization effect. However, when I apply this to another machine with poorer performance, it may produces negative effect and even sometimes makes the process hang. I think the cause is excessive CPU resource preemption with the parallelism enhanced at the C++ level (#44310) landed at the same time. P.S. I also tested the optimization of C++ in the same environment, and that one can always achieve a considerable optimization effect.
Therefore, considering of better versatility, I prefer to set the default value of num_threads to 1, i.e. modify the value here to num_threads = num_threads or 1, which can keep consistent with the previous codes by default, and work positively if user set it manually. In addition, we can explain the risk and recommended value of this parameter in the comments.
Look forward to your suggestions.
|
I would also go with 1 thread by default to maintain compatibility. Alternatively, minimum between number of patterns and number of cores. |
|
@mihaimaruseac |
|
There seems to be a internal failed check in the ci process. Could you please help to see if something went wrong? |
|
It is imported internally, pending some additional review. I'll come back here if there's more to do, but for now this is all good. |
@mihaimaruseac Okay, thanks for pushing forward! |
|
An API owners comment:
I think this should possible. What do you think? |
@mihaimaruseac If so, first of all, I think On the other hand, this will also result in more changes, including input formats for C++ Op. So I prefer to preserve python's multiprocesses for now. Of course, if the owner sticks to this point, I can also make the changes, but it may take more time and more disscussion. Thanks anyway! |
|
We can change C++ API (and update the goldens files), it is not an issue, as long as Python API maintains compatibility. Seems python multiprocessing has issues so it's preferable to push this code to C++. |
Sorry for the late reply... |
|
@firejq Can you please resolve conflicts? Thanks! |
|
Due to other tighter issues in the near future, I will temporarily close this pr, and reopen it if there are new developments in the future. Thanks to all reviewers! |
This is a PR from JIZHI Team & TaiJi AI platform in Tencent.
Add a argument
max_parallel_numfortf.gfile.Glob, which will setup a threadpool to parallelize the matching for mulitple pattern strings. It can bring nice performance improvement ifmax_parallel_numis set appropriately.Thanks for your review.