-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create highspeed_write_nonzero.py #1628
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
import shutil | ||
import time | ||
import argparse | ||
import subprocess | ||
import mmap | ||
import io | ||
from multiprocessing import Pool, cpu_count | ||
|
||
|
||
# Function to create files using dd command | ||
def create_file_dd(file_index, folder, source_file, timestamp): | ||
filename = os.path.join(folder, f'ddFile_{timestamp}_{file_index}') | ||
block_size = 1 # in GB | ||
count = 36 | ||
file_size_gb = (block_size * count) | ||
|
||
command = f"dd if={source_file} of={filename} bs={block_size}G count={count} oflag=direct" | ||
|
||
start_time = time.time() | ||
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
end_time = time.time() | ||
|
||
if result.returncode != 0: | ||
return (filename, 0, 0.0, f"Error creating file {filename}: {result.stderr.decode().strip()}") | ||
|
||
write_time = end_time - start_time | ||
write_speed = (file_size_gb * 1024) / write_time # MB/s | ||
|
||
return (filename, write_time, write_speed, file_size_gb, None) | ||
|
||
# Main function to handle parallel execution | ||
def main(folder, num_files, source_file): | ||
if not os.path.exists(folder): | ||
os.makedirs(folder) | ||
|
||
timestamp = int(time.time()) # Get current timestamp for file naming | ||
|
||
start_time = time.time() | ||
results = [] | ||
|
||
|
||
with Pool(processes=cpu_count()) as pool: # Pool of workers based on the CPU count | ||
futures=[] | ||
futures += [pool.apply_async(create_file_dd, (i, folder, source_file, timestamp)) for i in range(num_files)] | ||
|
||
# Collect results from async operations | ||
for future in futures: | ||
result = future.get() | ||
if result[4] is None: # No error | ||
results.append(result) | ||
else: | ||
print(result[4]) # Print error messages | ||
|
||
end_time = time.time() | ||
|
||
total_time = end_time - start_time | ||
total_data_written = sum(r[3] for r in results) # in GB | ||
speed_gbps = (total_data_written *8 ) / total_time # Convert GB to Gigabits (1 GB = 8 Gb) | ||
|
||
throughput = (total_data_written * 1024) / total_time | ||
print(f"Number of files written: {num_files}") | ||
print(f"Total amount of data written: {total_data_written:.2f} GB") | ||
print(f"Total time taken: {total_time:.2f} seconds") | ||
print(f"Overall Speed: {speed_gbps:.2f} Gbps") | ||
print(f"Throughput: {throughput:.2f} MiB/s") | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Create multiple files using various methods in parallel.') | ||
parser.add_argument('folder', type=str, help='The folder where the files will be written.') | ||
parser.add_argument('num_files', type=int, help='The number of files to create.') | ||
parser.add_argument('source_file', type=str, help='The source file to copy data from.') | ||
|
||
args = parser.parse_args() | ||
main(args.folder, args.num_files, args.source_file) | ||
|
||
# python3 highspeed_write_nonzero.py <mntPath>~/drs/random_data_test/ <noOfFiles>5 <sourceFile>/mnt/azcopy_test_180GB.log |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using this script in the pipeline anywhere or its just for testing manually for high speed writes.