Skip to content

Commit b329028

Browse files
committed
prefer batch_size in batched async methods
1 parent 079867b commit b329028

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

adlfs/spec.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ def __init__(
297297
if self.credential is not None:
298298
weakref.finalize(self, sync, self.loop, close_credential, self)
299299

300-
self.max_concurrency = max_concurrency or (_get_batch_size() // 4)
300+
if max_concurrency is None:
301+
batch_size = _get_batch_size()
302+
if batch_size > 0:
303+
max_concurrency = batch_size
304+
self.max_concurrency = max_concurrency
301305

302306
@classmethod
303307
def _strip_protocol(cls, path: str):
@@ -1453,6 +1457,12 @@ async def _pipe_file(
14531457

14541458
pipe_file = sync_wrapper(_pipe_file)
14551459

1460+
async def _pipe(self, *args, batch_size=None, max_concurrency=None, **kwargs):
1461+
max_concurrency = max_concurrency or 1
1462+
return await super()._pipe(
1463+
*args, batch_size=batch_size, max_concurrency=max_concurrency, **kwargs
1464+
)
1465+
14561466
async def _cat_file(
14571467
self, path, start=None, end=None, max_concurrency=None, **kwargs
14581468
):
@@ -1512,6 +1522,12 @@ def cat(self, path, recursive=False, on_error="raise", **kwargs):
15121522
else:
15131523
return self.cat_file(paths[0])
15141524

1525+
async def _cat_ranges(self, *args, batch_size=None, max_concurrency=None, **kwargs):
1526+
max_concurrency = max_concurrency or 1
1527+
return await super()._cat_ranges(
1528+
*args, batch_size=batch_size, max_concurrency=max_concurrency, **kwargs
1529+
)
1530+
15151531
def url(self, path, expires=3600, **kwargs):
15161532
return sync(self.loop, self._url, path, expires, **kwargs)
15171533

@@ -1656,6 +1672,12 @@ async def _put_file(
16561672

16571673
put_file = sync_wrapper(_put_file)
16581674

1675+
async def _put(self, *args, batch_size=None, max_concurrency=None, **kwargs):
1676+
max_concurrency = max_concurrency or 1
1677+
return await super()._put(
1678+
*args, batch_size=batch_size, max_concurrency=max_concurrency, **kwargs
1679+
)
1680+
16591681
async def _cp_file(self, path1, path2, **kwargs):
16601682
"""Copy the file at path1 to path2"""
16611683
container1, path1, version_id = self.split_path(path1, delimiter="/")
@@ -1722,6 +1744,12 @@ async def _get_file(
17221744

17231745
get_file = sync_wrapper(_get_file)
17241746

1747+
async def _get(self, *args, batch_size=None, max_concurrency=None, **kwargs):
1748+
max_concurrency = max_concurrency or 1
1749+
return await super()._get(
1750+
*args, batch_size=batch_size, max_concurrency=max_concurrency, **kwargs
1751+
)
1752+
17251753
def getxattr(self, path, attr):
17261754
meta = self.info(path).get("metadata", {})
17271755
return meta[attr]

0 commit comments

Comments
 (0)