Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CPU-bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from hashlib import md5
from random import choice
import concurrent.futures
from time import time


def is_prime(n):
while True:
s = "".join([choice("0123456789") for i in range(50)])
h = md5(s.encode('utf8')).hexdigest()

if h.endswith("00000"):
return s + ',' + h


def main():
with concurrent.futures.ProcessPoolExecutor(max_workers=2) as executor:
for answer in zip(executor.map(is_prime, range(3))):
print(answer)


if __name__ == '__main__':
time1 = time()
main()
time2 = time()
print(time2 - time1)
22 changes: 22 additions & 0 deletions IO-bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import urllib.request
from urllib.parse import unquote
import concurrent.futures

links = open('res.txt', encoding='utf8').read().split('\n')


def load_url(link, timeout):
with urllib.request.urlopen(link, timeout=timeout) as conn:
return conn.code


with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
future_to_url = {executor.submit(load_url, url, 5): url for url in links}
for future in concurrent.futures.as_completed(future_to_url):
url = future_to_url[future]
try:
data = future.result()
except Exception as e:
print('%r exception: %s' % (url, e))
else:
print(data)
110 changes: 110 additions & 0 deletions otchet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
## IO-bound

### Выполнение синхронно, в 1 поток:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/io-bound(%D1%81%D0%B8%D0%BD%D1%85%D1%80%2C%20%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/io-bound(%D1%81%D0%B8%D0%BD%D1%85%D1%80%D0%BE%D0%BD%D0%BD%D1%8B%D0%B9).jpg'>


### Выполнение используя ThreadPoolExecutor:

### воркер = 5:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/скрины/io-b2(время).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/io-b2(%D0%94%D0%B7).jpg'>

### воркер = 10:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/io-b2(10%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/10.jpg'>
<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/10(2).jpg'>

### воркер = 100:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/io-b2(100%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/io-b2(100%D0%94%D0%B7).jpg'>


При преобразование время выполнения уменьшается, а загрузка памяти почти не отличается, процессор(цп) в основном тоже одинаков, но бывают моменты когда скачок и становится больше


##CPU-bound:

### Выполнение на 1 ядре:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b1(%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/скрины/cpu-b1(дз).jpg'>

### Выполнение используя ProcessPoolExecutor:

### Воркаут = 2:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b2(%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b2(%D0%94%D0%B7).jpg'>

### Воркаут = 4:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b4(%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b4(%D0%B4%D0%B7).jpg'>

### Воркаут = 5:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b5(%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b5(%D0%B4%D0%B7).jpg'>

### Воркаут = 10:

время выполнения:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b10(%D0%B2%D1%80%D0%B5%D0%BC%D1%8F).jpg'>

Диспечер задач:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b10(%D0%B4%D0%B7).jpg'>

### Воркаут = 100:

<img src='https://github.com/NastyaBay/multi-task-at-18/blob/main/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%D1%8B/cpu-b100.jpg'>

При увеличении с 2 на 4 воркаута увеличивается загруженость процессора(ЦП) до 100%, что означает что все(4) ядра заняты. При этом время уменьшается(быстрее проходит), после 4 и до 61 будет примерно одинаковые значения, которые уже рандомны(так как монеты формируем случайно(+ отбираем нужный)) воркаут = 100 не проходит(ошибка: возможно толкьо до 61)

Loading