Я только что развернул m5.4xlarge
на AWS, чтобы проверить производительность многопроцессорной обработки, и получаю странные результаты.
multiprocessing.cpu_count()
возвращает 16
#home I5-3570K 4cores/4threads, with a pool size of 4 : Computation took 5.15700006485 seconds
#aws m5.4xlarge 16 threads, with a pool size of 4 : Computation took 3.80112195015 seconds
#aws m5.4xlarge 16 threads, with a pool size of 8 : Computation took 3.77861309052 seconds
#aws m5.4xlarge 16 threads, with a pool size of 15 : Computation took 3.26295304298 seconds
#aws m5.4xlarge 16 threads, with a pool size of 16 : Computation took 4.16541814804 seconds
Я что-то сделал не такв моем сценарии?
# coding: utf-8
import hashlib
import time
from multiprocessing import Pool
#on a fresh AWS linux instance run :
#sudo yum groupinstall "Development Tools"
#sudo easy_install hashlib
def compute_hash_256(very_random_string):
return hashlib.sha256(very_random_string).hexdigest()
if __name__ == '__main__':
POOL_SIZE = 16 #number of threads of our computer
pool = Pool(processes=POOL_SIZE)
########################### generates strings for hashing
N_STRINGS = 3000000
print "Generating {} strings for hashing...".format(N_STRINGS)
random_strings = []
padding_size = len(str(N_STRINGS))
for i in range(N_STRINGS):
random_strings.append(str(i).zfill(padding_size))
############################ hashes the strings using multiprocessing
print "Computing {} hashes".format(len(random_strings))
start = time.time()
hashes = pool.map(compute_hash_256, random_strings)
end = time.time()
print "Computation took {} seconds".format(end-start)
Спасибо