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.

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.

10 changes: 10 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.

22 changes: 22 additions & 0 deletions CPU-bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from hashlib import md5
from random import choice
import concurrent.futures


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

if h.endswith("00000"):
return f"{s}, {h}"


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


if __name__ == '__main__':
main()
23 changes: 23 additions & 0 deletions IO-bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import urllib
from urllib.request import Request, urlopen
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)
92 changes: 92 additions & 0 deletions report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
## IO-bound
**В один поток**

время
![time_thread 1](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_thread_1.jpg)

нагрузка
![load_thread 1](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_thread_1.jpg)

**используя ThreadPoolExecutor**
**worker = 5**

время
![time_thread 5](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_thread_5.jpg)

нагрузка
![load_thread 5](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_thread_5.jpg)


**worker = 10**

время
![time_thread 10](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_thread_10.jpg)

нагрузка
![load_thread 10](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_thread_10.jpg)


**worker = 100**

время
![time_thread 100](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_thread_100.jpg)

нагрузка
![load_thread 100](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_thread_100.jpg)

**Вывод:** Скорость обработки значительно увеличивается используя многопоточность, нагрузка на ЦП плавно увеличивается с ростом количества потоков, количество памяти слабо изменяется, а нагрузка на сеть также плавно увеличивается.

## CPU-bound

**На одном ядре**

время
![time_cpu 1](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_cpu_1.jpg)

нагрузка
![load_cpu 1](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_cpu_1.jpg)

**используя ThreadPoolExecutor**
**worker = 2**

время
![time_cpu 2](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_cpu_2.jpg)

нагрузка
![load_cpu 2](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_cpu_2.jpg)


**worker = 4**

время
![time_cpu 4](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_cpu_4.jpg)

нагрузка
![load_cpu 4](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_cpu_4.jpg)


**worker = 5**

время
![time_cpu 5](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_cpu_5.jpg)

нагрузка
![load_cpu 5](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_cpu_5.jpg)


**worker = 10**

время
![time_cpu 10](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/time_cpu_10.jpg)

нагрузка
![load_cpu 10](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/load_cpu_10.jpg)

**worker = 100**

Выдает ошибку
![cpu error](https://github.com/BobylevTimofey/multi-task-at-20/blob/Бобылев_Тимофей/screens/cpu_error.jpg)

Ошибка возникает из-за того, что windows накладывает ограничение и не дает создать больше 61 воркера

**Вывод:** Использование 2 ядер ускоряет выполнение программы. Но дальнейший прирост ядер не дает результата т.к. на используемом компьютере только два логических ядра. Программа с использованием двух и более ядер выполняется за примерно одно и то же время(разброс во времени связан со случайностью в вычислениях монет). Это показывает и нагрузка ЦП для двух и более ядер она составляет примерно 85%
Loading