Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.file_pool; | 5 library barback.file_pool; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 /// time a file finishes being read or a new file is opened. If it fires, that | 31 /// time a file finishes being read or a new file is opened. If it fires, that |
| 32 /// indicates that the caller became deadlocked, likely due to files waiting | 32 /// indicates that the caller became deadlocked, likely due to files waiting |
| 33 /// for additional files to be read before they could be closed. | 33 /// for additional files to be read before they could be closed. |
| 34 Timer _timer; | 34 Timer _timer; |
| 35 | 35 |
| 36 /// The number of files currently open in the pool. | 36 /// The number of files currently open in the pool. |
| 37 int _openFiles = 0; | 37 int _openFiles = 0; |
| 38 | 38 |
| 39 /// The maximum number of file descriptors that the pool will allocate. | 39 /// The maximum number of file descriptors that the pool will allocate. |
| 40 /// | 40 /// |
| 41 /// Barback may only use half the available file descriptors. | 41 /// This is based on empirical tests that indicate that beyond 32, additional |
| 42 int get _maxOpenFiles => (maxFileDescriptors / 2).floor(); | 42 /// file reads don't provide substantial additional throughput. |
| 43 final int _maxOpenFiles = 32; | |
|
dgrove
2013/10/22 20:31:48
Did you try measuring this on a variety of compute
| |
| 43 | 44 |
| 44 /// Opens [file] for reading. | 45 /// Opens [file] for reading. |
| 45 /// | 46 /// |
| 46 /// When the returned stream is listened to, if there are too many files | 47 /// When the returned stream is listened to, if there are too many files |
| 47 /// open, this will wait for a previously opened file to be closed and then | 48 /// open, this will wait for a previously opened file to be closed and then |
| 48 /// try again. | 49 /// try again. |
| 49 Stream<List<int>> openRead(File file) { | 50 Stream<List<int>> openRead(File file) { |
| 50 var reader = new _FileReader(this, file); | 51 var reader = new _FileReader(this, file); |
| 51 if (_openFiles < _maxOpenFiles) { | 52 if (_openFiles < _maxOpenFiles) { |
| 52 _openFiles++; | 53 _openFiles++; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 _onDone(); | 176 _onDone(); |
| 176 } | 177 } |
| 177 | 178 |
| 178 /// Handles the underlying file stream finishing. | 179 /// Handles the underlying file stream finishing. |
| 179 void _onDone() { | 180 void _onDone() { |
| 180 _subscription = null; | 181 _subscription = null; |
| 181 _controller.close(); | 182 _controller.close(); |
| 182 _pool._startPendingListen(); | 183 _pool._startPendingListen(); |
| 183 } | 184 } |
| 184 } | 185 } |
| OLD | NEW |