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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/multi-task-at-20.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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=100) 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)
126 changes: 126 additions & 0 deletions report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# IO-Bound задача
## Выполнение синхронно в 1 поток:
Время выполнения:

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_task2.png)


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

### 5 воркеров

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

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x5_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x5_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x5_task2.png)

### 10 воркеров

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

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x10_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x10_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x10_task2.png)

### 100 воркеров

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

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x100_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x100_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/io_x100_task2.png)

### Вывод:

При использовании ThreadPoolExecutor загрузка памяти значительно уменьшилась.
При увеличении количества воркеров время выполнения программы уменьшается, а загрузка памяти практически не отличается, за исключением редких скачков.

# CPU-Bound задача

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

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

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_task2.png)


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

### 2 воркера

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

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x2_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x2_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x2_task2.png)

### 4 воркера

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

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x4_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x4_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x4_task2.png)

### 10 воркеров

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

![Время выполнения](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x10_prof.png)

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


![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x10_task1.png)

![Диспетчер задач](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x10_task2.png)

### 100 воркеров

![Ошибка](https://github.com/nicosare/multi-task-at-20/blob/%D0%93%D0%B0%D0%BB%D0%BA%D0%B8%D0%BD_%D0%94%D0%B0%D0%BD%D0%B8%D0%B8%D0%BB/screenshots/cpu_x100_err.png)

### Вывод:

При использовании ProcessPoolExecutor время работы программы уменьшилось, а загруженность процессора поднялась до 90% с редкими скачками до 100%, что означает, что все 2 ядра полностью заняты.
При увеличении количества воркеров с 2 до 10 (количество воркеров больше, чем количество ядер) время работы и загруженность процессора практически не изменяются, так как на компьютере имеется всего 2 ядра и 2 логических процессора.
При количестве воркеров = 100 происходит ошибка, так как их количество не может превышать 61.
Loading