xref: /aosp_15_r20/external/aws-sdk-java-v2/test/s3-benchmarks/.scripts/benchmark-dir (revision 8a52c7834d808308836a99fc2a6e0ed8db339086)
1*8a52c783SCole Faust#!/bin/bash
2*8a52c783SCole Faust
3*8a52c783SCole Faust#
4*8a52c783SCole Faust# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5*8a52c783SCole Faust#
6*8a52c783SCole Faust# Licensed under the Apache License, Version 2.0 (the "License").
7*8a52c783SCole Faust# You may not use this file except in compliance with the License.
8*8a52c783SCole Faust# A copy of the License is located at
9*8a52c783SCole Faust#
10*8a52c783SCole Faust#  http://aws.amazon.com/apache2.0
11*8a52c783SCole Faust#
12*8a52c783SCole Faust# or in the "license" file accompanying this file. This file is distributed
13*8a52c783SCole Faust# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14*8a52c783SCole Faust# express or implied. See the License for the specific language governing
15*8a52c783SCole Faust# permissions and limitations under the License.
16*8a52c783SCole Faust#
17*8a52c783SCole Faust
18*8a52c783SCole Faust# Script for running multiple Transfer manager benchmarks at the same time
19*8a52c783SCole Faust
20*8a52c783SCole Faustusage() {
21*8a52c783SCole Faust  echo "usage:"
22*8a52c783SCole Faust  echo "    benchmark-dir download|upload fs|tmpfs|no-op [1B|4K|16M|5G]"
23*8a52c783SCole Faust  echo "example:"
24*8a52c783SCole Faust  echo "    ./benchmark-dir download fs"
25*8a52c783SCole Faust  echo "    ./benchmark-dir upload tmpfs"
26*8a52c783SCole Faust  echo "    ./benchmark download fs 5G"
27*8a52c783SCole Faust}
28*8a52c783SCole Faust
29*8a52c783SCole Faust# validate operation
30*8a52c783SCole Faustif [ -z "$1" ] || ([ "$1" != download ] && [ "$1" != upload ]); then
31*8a52c783SCole Faust  usage
32*8a52c783SCole Faust  exit 1
33*8a52c783SCole Faustfi
34*8a52c783SCole Faustoperation="$1"_directory
35*8a52c783SCole Faust
36*8a52c783SCole Faust# validate location
37*8a52c783SCole Faustif [[ -z "$2" ]]; then
38*8a52c783SCole Faust  usage
39*8a52c783SCole Faust  exit 1
40*8a52c783SCole Faustfi
41*8a52c783SCole Faust
42*8a52c783SCole Faustlocation_name="$2"
43*8a52c783SCole Faustif ([ "$location_name" != fs ] && [ "$location_name" != tmpfs ] && [ "$location_name" != no-op ]); then
44*8a52c783SCole Faust  usage
45*8a52c783SCole Faust  exit 1
46*8a52c783SCole Faustfi
47*8a52c783SCole Faust
48*8a52c783SCole Faustif [[ "$location_name" == fs ]]; then
49*8a52c783SCole Faust  location="$HOME/tm_dir_files"
50*8a52c783SCole Faustfi
51*8a52c783SCole Faust
52*8a52c783SCole Faustif [[ "$location_name" == tmpfs ]]; then
53*8a52c783SCole Faust  location="/dev/shm/tm_dir_files"
54*8a52c783SCole Faustfi
55*8a52c783SCole Faust
56*8a52c783SCole Faust
57*8a52c783SCole Faustsizes_str="1B 4K 16M 5G"
58*8a52c783SCole Faustversions_str="v1 v2"
59*8a52c783SCole Faustsizes=( $sizes_str )
60*8a52c783SCole Faustversions=( $versions_str )
61*8a52c783SCole Faust
62*8a52c783SCole Faustrun_benchmark() {
63*8a52c783SCole Faust  echo "Benchmark: $version - $size"
64*8a52c783SCole Faust  directory="$location/$size"
65*8a52c783SCole Faust  if [[ -z "$directory" ]]; then
66*8a52c783SCole Faust    mkdir -p "$directory"
67*8a52c783SCole Faust  fi
68*8a52c783SCole Faust  result_file="$operation"_"$location_name"_"$version"_"$size".txt
69*8a52c783SCole Faust  prefix="$size"
70*8a52c783SCole Faust  cmd="java -jar ../target/s3-benchmarks.jar \
71*8a52c783SCole Faust            --operation=$operation \
72*8a52c783SCole Faust            --bucket=do-not-delete-crt-s3-eu-west-1 \
73*8a52c783SCole Faust            --partSizeInMB=8 \
74*8a52c783SCole Faust            --maxThroughput=100.0 \
75*8a52c783SCole Faust            --iteration=8 \
76*8a52c783SCole Faust            --version=$version \
77*8a52c783SCole Faust            --readBufferInMB=3072 \
78*8a52c783SCole Faust            --prefix=$prefix \
79*8a52c783SCole Faust            --file=$directory"
80*8a52c783SCole Faust
81*8a52c783SCole Faust  echo "$cmd" | sed 's/ \{1,\}/ /g' > "result/$result_file"
82*8a52c783SCole Faust  $cmd | tee -a "result/$result_file"
83*8a52c783SCole Faust  echo "Benchmark done"
84*8a52c783SCole Faust}
85*8a52c783SCole Faust
86*8a52c783SCole Faustfor (( i = 0; i < "${#versions[@]}"; i++ ))
87*8a52c783SCole Faustdo
88*8a52c783SCole Faust  version="${versions[$i]}"
89*8a52c783SCole Faust  if [[ -n "$3" ]]
90*8a52c783SCole Faust  then
91*8a52c783SCole Faust    size="$3"
92*8a52c783SCole Faust    run_benchmark
93*8a52c783SCole Faust  else
94*8a52c783SCole Faust    for (( j = 0; j < "${#sizes[@]}"; j++ ))
95*8a52c783SCole Faust    do
96*8a52c783SCole Faust      size="${sizes[$j]}"
97*8a52c783SCole Faust      run_benchmark
98*8a52c783SCole Faust    done
99*8a52c783SCole Faust  fi
100*8a52c783SCole Faustdone
101*8a52c783SCole Faust
102*8a52c783SCole Faust
103