github.com/yandex-cloud/geesefs@v0.40.9/bench/gen_small.py (about)

     1  #!/usr/bin/python3
     2  
     3  import sys, os, random
     4  
     5  if len(sys.argv) < 2:
     6      print("USAGE: python3 gen_small.py DIR [COUNT] [MAX_SIZE]")
     7      print("Creates COUNT files under DIR, sharded over 1024 2-level deep subdirectories")
     8      print("Files will be 0.5 KB - MAX_SIZE KB, skewed to smaller sizes")
     9      print("Default COUNT and MAX_SIZE are 6400 and 300 KB")
    10      exit(1)
    11  d = sys.argv[1]+'/'
    12  if len(sys.argv) > 2:
    13      n = int(sys.argv[2])
    14  else:
    15      n = 6400
    16  if len(sys.argv) > 3:
    17      maxsize = int(sys.argv[3])*1000
    18  else:
    19      maxsize = 300000
    20  
    21  # N small files, 0.5-maxsize kb in size, 1/10 on average, sharded across 1024 dirs
    22  for i in range(n):
    23      size = 512+int((random.random()**10)*maxsize)
    24      os.makedirs(d+str(i%32)+'/'+str(int(i/32)%32), 0o777, True)
    25      f = open(d+str(i%32)+'/'+str(int(i/32)%32)+'/'+str(i), 'wb')
    26      f.write(os.urandom(size))
    27      f.close()
    28  
    29  # fsync
    30  os.fsync(os.open(d, os.O_RDONLY))