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
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 miner(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 token in zip(executor.map(miner, range(5))):
print(token)


if __name__ == '__main__':
main()
24 changes: 24 additions & 0 deletions IO-bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import concurrent.futures
import urllib.request

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


# Retrieve a single page and report the URL and contents
def load_url(url, timeout):
with urllib.request.urlopen(url, timeout=timeout) as conn:
return conn.read()


# We can use a with statement to ensure threads are cleaned up promptly
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
# Start the load operations and mark each future with its URL
future_to_url = {executor.submit(load_url, url, 60): url for url in URLS}
for future in concurrent.futures.as_completed(future_to_url):
url = future_to_url[future]
try:
data = future.result()
except Exception as exc:
print('%r generated an exception: %s' % (url, exc))
else:
print('%r page is %d bytes' % (url, len(data)))
54 changes: 54 additions & 0 deletions REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# IO-bound
## Синхронная проверка ссылок:
### Время выполнения
![img.png](Screens/io_time1.png)
### Диспетчер задач
![img.png](Screens/io_tm1.png)
## Используя ThreadPoolExecutor:
## Воркер 5:
### Время
![img.png](Screens/io_time2.png)
### Диспетчер
![img.png](Screens/io_tm2.png)
## Воркер 10:
### Время
![img.png](Screens/io_time3.png)
### Диспетчер
![img.png](Screens/io_tm3.png)
## Воркер 100:
### Время
![img.png](Screens/io_time4.png)
### Диспетчер
![img.png](Screens/io_tm4.png)
Загрузка памяти почти не отличается, загрузка ЦП совсем немного увеличивается. Но время выполнения существенно сокращается
# CPU-bound
Замер будет на поиске 5-и монет
## Скорость генерации на 1 ядре
### Время
![img.png](Screens/cpu_time1.png)
### Диспетчер
![img.png](Screens/cpu_tm1.png)
## Используя ProcessPoolExecutor:
## Воркер 2:
### Время
![img.png](Screens/cpu_time2.png)
### Диспетчер
![img.png](Screens/cpu_tm2.png)
## Воркер 4:
### Время
![img.png](Screens/cpu_time3.png)
### Диспетчер
![img.png](Screens/cpu_tm3.png)
## Воркер 5:
### Время
![img.png](Screens/cpu_time4.png)
### Диспетчер
![img.png](Screens/cpu_tm4.png)
## Воркер 10:
### Время
![img.png](Screens/cpu_time5.png)
### Диспетчер
![img.png](Screens/cpu_tm5.png)
## Воркер 100:
![img.png](Screens/cpu_time6.png)
Сильно меняется загрузка процессора, время выполнения уменьшается с увеличением количества воркеров. Максимальное количество воркеров - 61 из-за особенностей ОС.
Binary file added Screens/cpu_time1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_time2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_time3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_time4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_time5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_time6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_tm1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_tm2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_tm3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_tm4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/cpu_tm5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_time1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_time2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_time3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_time4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_tm1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_tm2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_tm3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screens/io_tm4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
985 changes: 985 additions & 0 deletions res.txt

Large diffs are not rendered by default.