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-19.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.

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

def get_coin():
while True:
s = "".join([choice("0123456789") for i in range(50)])
h = md5(s.encode('utf8')).hexdigest()
res = ""
if h.endswith("00000"):
return s, h

def find_coin(workers, count):
with concurrent.futures.ProcessPoolExecutor(max_workers=workers) as executor:
for i in range(count):
executor.submit(get_coin)

if __name__ == '__main__':
find_coin(61, 4)
18 changes: 18 additions & 0 deletions Generate_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from urllib.request import urlopen
from urllib.parse import unquote
from bs4 import BeautifulSoup
from tqdm import tqdm

url = 'https://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:%D0%A1%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0'

res = open('res.txt', 'w', encoding='utf8')

for i in tqdm(range(100)):
html = urlopen(url).read().decode('utf8')
soup = BeautifulSoup(html, 'html.parser')
links = soup.find_all('a')

for l in links:
href = l.get('href')
if href and href.startswith('http') and 'wiki' not in href:
print(href, file=res)
22 changes: 22 additions & 0 deletions IO-bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import concurrent.futures
import urllib.request

links = 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 links}
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)))
Binary file added Pic/a1.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 Pic/a2.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 Pic/a3.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 Pic/a4.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 Pic/c1.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 Pic/c2.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 Pic/c3.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 Pic/c4.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 Pic/c5.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 Pic/c6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Отчет по работе «Параллелизм и асинхронность»
IO-BOUND
Время работы IO_bound.py при синхронной проверке ссылок – 10057 ms

![alt text](Pic/a1.png)

Перепишем код, используя ThreadPoolExecutor. Благодар этому время работы изменилось.
Когда количество воркеров(потоков):
5 - 5460 ms
![alt text](Pic/a2.png)
10 - 4736 ms
![alt text](Pic/a3.png)
100 - 4176 ms
![alt text](Pic/a4.png)

Таким образом, при увеличение количества потоков, увеличение используемой памяти и загрузки процессора не происходит, и при этом дает выигрыш в скорости (времени) выполнения кода.

#CPU-BOUND
Время генерации четырех монет - 162764 ms
![alt text](Pic/c1.png)
Перепишем код используя ProcessPoolExecutor.
При max_workers=2 время работы - 125920 ms
![alt text](Pic/c2.png)
При max_workers=4 время работы - 71804 ms
![alt text](Pic/c3.png)
При max_workers=5 время работы - 61158 ms
![alt text](Pic/c4.png)
При max_workers=10 время работы - 57459 ms
![alt text](Pic/c5.png)
При max_workers=100 время работы - 71784 ms
![alt text](Pic/c6.png)
Увеличение количества процессов влечет за собой увеличение используемой памяти и загрузки процессора, но при этом дает выигрыш в скорости (времени) выполнения кода, если количество процессов не превышает числа физических ядер
17 changes: 17 additions & 0 deletions res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
http://www.warheroes.ru/hero/hero.asp?Hero_id=14666
http://2.bp.blogspot.com/_bgY8-dFngM4/TQ82RVqrTKI/AAAAAAAAAJk/nBUHeDwei2I/s1600/O+zi+in+Mongolia+-+B.+Sharav+%281869-1939%29.jpg
http://www.zurag.de/zurag-film.html
https://libris.kb.se/katalogisering/hftx31m15ch5sm3
http://pagad-ultimo.livejournal.com/5040.html
http://www.powys-society.org
https://www.treccani.it/enciclopedia/giovanni-maria-angiolello_(Dizionario-Biografico)
http://talishvestnik.narod.ru
http://talishvestnik.narod.ru/index.html
https://findsmi.ru/56946
http://spider.seds.org/ngc/ngc.cgi?6636-1
http://spider.seds.org/ngc/ngc_fr.cgi?6636-1
http://spider.seds.org/ngc/revngcic.cgi?NGC6636-1
http://vizier.u-strasbg.fr/viz-bin/VizieR-S?NGC+6636-1
http://nedwww.ipac.caltech.edu/cgi-bin/nph-objsearch?objname=NGC+6636-1
http://adsabs.harvard.edu/cgi-bin/basic_connect?qsearch=%22NGC+6636-1%22&version=1
http://www.cbat.eps.harvard.edu/lists/Supernovae.html