Make computeFSClosure() single-threaded again
The fact that queryPathInfo() is synchronous meant that we needed a thread for every concurrent binary cache lookup, even though they end up being handled by the same download thread. Requiring hundreds of threads is not a good idea. So now there is an asynchronous version of queryPathInfo() that takes a callback function to process the result. Similarly, enqueueDownload() now takes a callback rather than returning a future. Thus, a command like nix path-info --store https://cache.nixos.org/ -r /nix/store/slljrzwmpygy1daay14kjszsr9xix063-nixos-16.09beta231.dccf8c5 that returns 4941 paths now takes 1.87s using only 2 threads (the main thread and the downloader thread). (This is with a prewarmed CloudFront.)
This commit is contained in:
		
							parent
							
								
									054be50257
								
							
						
					
					
						commit
						75989bdca7
					
				
					 16 changed files with 410 additions and 227 deletions
				
			
		|  | @ -376,4 +376,43 @@ string get(const T & map, const string & key, const string & def = "") | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| /* Call ‘failure’ with the current exception as argument. If ‘failure’
 | ||||
|    throws an exception, abort the program. */ | ||||
| void callFailure(const std::function<void(std::exception_ptr exc)> & failure); | ||||
| 
 | ||||
| 
 | ||||
| /* Evaluate the function ‘f’. If it returns a value, call ‘success’
 | ||||
|    with that value as its argument. If it or ‘success’ throws an | ||||
|    exception, call ‘failure’. If ‘failure’ throws an exception, abort | ||||
|    the program. */ | ||||
| template<class T> | ||||
| void sync2async( | ||||
|     const std::function<void(T)> & success, | ||||
|     const std::function<void(std::exception_ptr exc)> & failure, | ||||
|     const std::function<T()> & f) | ||||
| { | ||||
|     try { | ||||
|         success(f()); | ||||
|     } catch (...) { | ||||
|         callFailure(failure); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /* Call the function ‘success’. If it throws an exception, call
 | ||||
|    ‘failure’. If that throws an exception, abort the program. */ | ||||
| template<class T> | ||||
| void callSuccess( | ||||
|     const std::function<void(T)> & success, | ||||
|     const std::function<void(std::exception_ptr exc)> & failure, | ||||
|     T && arg) | ||||
| { | ||||
|     try { | ||||
|         success(arg); | ||||
|     } catch (...) { | ||||
|         callFailure(failure); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue