Real init
This commit is contained in:
parent
bf137e3f72
commit
765a204025
1 changed files with 3 additions and 7 deletions
10
fileshare.py
10
fileshare.py
|
@ -10,10 +10,9 @@ from tqdm import tqdm
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
# Optimize buffer settings
|
CHUNK_SIZE = 256 * 1024
|
||||||
CHUNK_SIZE = 256 * 1024 # 256KB
|
MAX_BUFFER = 4 * 1024 * 1024
|
||||||
MAX_BUFFER = 4 * 1024 * 1024 # 4MB
|
MIN_CHUNK_SIZE = 32 * 1024
|
||||||
MIN_CHUNK_SIZE = 32 * 1024 # 32KB
|
|
||||||
|
|
||||||
def format_size(size_bytes):
|
def format_size(size_bytes):
|
||||||
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
|
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
|
||||||
|
@ -53,7 +52,6 @@ async def file_handler(request):
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
# Synchronous file handling with async chunk processing
|
|
||||||
with open(file_path, 'rb') as f:
|
with open(file_path, 'rb') as f:
|
||||||
chunk_size = CHUNK_SIZE
|
chunk_size = CHUNK_SIZE
|
||||||
while True:
|
while True:
|
||||||
|
@ -61,7 +59,6 @@ async def file_handler(request):
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
await response.write(chunk)
|
await response.write(chunk)
|
||||||
# Dynamic buffer adjustment
|
|
||||||
chunk_size = min(MAX_BUFFER, max(MIN_CHUNK_SIZE, chunk_size * 2))
|
chunk_size = min(MAX_BUFFER, max(MIN_CHUNK_SIZE, chunk_size * 2))
|
||||||
|
|
||||||
duration = (datetime.now() - start_time).total_seconds()
|
duration = (datetime.now() - start_time).total_seconds()
|
||||||
|
@ -214,7 +211,6 @@ async def main_client(base_url, hash_file, parallel=None, timeout=3600):
|
||||||
print("\n🎉 All files are up to date!")
|
print("\n🎉 All files are up to date!")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Dynamic parallelism
|
|
||||||
if parallel is None:
|
if parallel is None:
|
||||||
parallel = min(ceil(len(download_list)/2), 20)
|
parallel = min(ceil(len(download_list)/2), 20)
|
||||||
parallel = max(1, min(parallel, 50))
|
parallel = max(1, min(parallel, 50))
|
||||||
|
|
Loading…
Add table
Reference in a new issue