diff --git a/cpu_bound.py b/cpu_bound.py new file mode 100644 index 0000000..42b983e --- /dev/null +++ b/cpu_bound.py @@ -0,0 +1,24 @@ +from concurrent.futures import ProcessPoolExecutor as PPE +from random import choice +from hashlib import md5 +import time + + +def gen_digit_and_hash(_): + result="" + hash="11111111" + while not hash.endswith("00000"): + string = "".join([choice("0123456789") for i in range(50)]) + hash = md5(string.encode('utf8')).hexdigest() + result=f"{string} - {hash}" + return result + +def main(): + with PPE(max_workers=10) as executor: + for string in executor.map(gen_digit_and_hash, [0 for _ in range(4)]): + print(string) + +if __name__ == '__main__': + start = time.time() + main() + print(time.time()-start) \ No newline at end of file diff --git a/getting_links.py b/getting_links.py new file mode 100644 index 0000000..967f17b --- /dev/null +++ b/getting_links.py @@ -0,0 +1,16 @@ +from bs4 import BeautifulSoup as BS +import tqdm +from urllib.request import urlopen + +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' + +with open('urls.txt', 'w', encoding='utf8') as result_file: + for i in tqdm.tqdm(range(20)): + html = urlopen(url).read().decode('utf8') + soup = BS(html, 'html.parser') + links = soup.find_all('a') + + for link in links: + href = link.get('href') + if href and (href.startswith('http://') or href.startswith('https://')) and 'wiki' not in href: + print(href, file=result_file) \ No newline at end of file diff --git a/img/CPU_1.png b/img/CPU_1.png new file mode 100644 index 0000000..e1bba96 Binary files /dev/null and b/img/CPU_1.png differ diff --git a/img/CPU_10.png b/img/CPU_10.png new file mode 100644 index 0000000..184da45 Binary files /dev/null and b/img/CPU_10.png differ diff --git a/img/CPU_10_load.png b/img/CPU_10_load.png new file mode 100644 index 0000000..88e4080 Binary files /dev/null and b/img/CPU_10_load.png differ diff --git a/img/CPU_2.png b/img/CPU_2.png new file mode 100644 index 0000000..83d112e Binary files /dev/null and b/img/CPU_2.png differ diff --git a/img/CPU_20.png b/img/CPU_20.png new file mode 100644 index 0000000..45bd3d8 Binary files /dev/null and b/img/CPU_20.png differ diff --git a/img/CPU_4.png b/img/CPU_4.png new file mode 100644 index 0000000..e783784 Binary files /dev/null and b/img/CPU_4.png differ diff --git a/img/CPU_61.png b/img/CPU_61.png new file mode 100644 index 0000000..0062201 Binary files /dev/null and b/img/CPU_61.png differ diff --git a/img/IO_1.png b/img/IO_1.png new file mode 100644 index 0000000..8e52597 Binary files /dev/null and b/img/IO_1.png differ diff --git a/img/IO_10.png b/img/IO_10.png new file mode 100644 index 0000000..4acaaab Binary files /dev/null and b/img/IO_10.png differ diff --git a/img/IO_100.png b/img/IO_100.png new file mode 100644 index 0000000..1fe801f Binary files /dev/null and b/img/IO_100.png differ diff --git a/img/IO_2.png b/img/IO_2.png new file mode 100644 index 0000000..55c36a1 Binary files /dev/null and b/img/IO_2.png differ diff --git a/img/IO_20.png b/img/IO_20.png new file mode 100644 index 0000000..7047418 Binary files /dev/null and b/img/IO_20.png differ diff --git a/img/IO_4.png b/img/IO_4.png new file mode 100644 index 0000000..aa83cda Binary files /dev/null and b/img/IO_4.png differ diff --git a/img/IO_50.png b/img/IO_50.png new file mode 100644 index 0000000..0cdb3a3 Binary files /dev/null and b/img/IO_50.png differ diff --git a/io_bound.py b/io_bound.py new file mode 100644 index 0000000..56b77b4 --- /dev/null +++ b/io_bound.py @@ -0,0 +1,28 @@ +import concurrent.futures as fut +from urllib.request import urlopen +import time + +links = open('urls.txt', encoding='utf8').read().split('\n') + + +def load_url(url, timeout): + with urlopen(url, timeout=timeout) as conn: + return conn.read() + +start = time.time() +with fut.ThreadPoolExecutor(max_workers=100) as executor: + future_to_url = dict() + + for url in links: + future_to_url[executor.submit(load_url, url, 20)] = url + + for future in fut.as_completed(future_to_url): + url = future_to_url[future] + try: + data=future.result() + except Exception as exception: + print(url," generated an exception", exception) + else: + print(f"{url} - {len(data)}") + +print(time.time()-start) \ No newline at end of file diff --git a/results.md b/results.md new file mode 100644 index 0000000..2761a22 --- /dev/null +++ b/results.md @@ -0,0 +1,69 @@ +# Параллелизм и асинхронность + +# IO Bound + +### Замер скорости 1 воркере: +Время: 337 секунд +![IO.png](img/IO_1.png) + +### Замер скорости 2 воркера: +Время: 155 секунд +![IO.png](img/IO_2.png) + +### Замер скорости 4 воркера: +Время: 60 секунд +![IO.png](img/IO_4.png) + +### Замер скорости 10 воркеров: +Время: 35 секунд +![IO.png](img/IO_10.png) + +### Замер скорости 20 воркеров: +Время: 28 секунд +![IO.png](img/IO_20.png) + +### Замер скорости 50 воркеров: +Время: 26 секунд +![IO.png](img/IO_50.png) + +### Замер скорости 100 воркеров: +Время: 27 секунд +![IO.png](img/IO_100.png) + +Изменение числа воркеров не сильно влияет на загрузку компьютера. +До 10 потоков потоков наблюдается линейний прирост в скорости. +После чего происходит происходит небольшой прирост на 20 потоках. +Далее, вероятно, происходит упор во время ожидания получения информации и никакого прироста не наблюдается. + +# CPU Bound + +### Замер скорости 1 воркере: + +![CPU.png](img/CPU_1.png) +Время: 22 секунды + +### Замер скорости 2 воркера: +Время: 31 секунда +![CPU.png](img/CPU_2.png) + +### Замер скорости 4 воркера: +Время: 8 секунд +![CPU.png](img/CPU_4.png) + +### Замер скорости 10 воркеров: +Время: 14 секунд +![CPU.png](img/CPU_10.png) + +### Замер скорости 20 воркеров: +Время: 26 секунд +![CPU.png](img/CPU_20.png) + +### Замер скорости 61 воркер: +Время: 90 секунд +![CPU.png](img/CPU_61.png) + +При увеличении числа потоков достаточно сильно возрастала нагрузка на процессор. +![CPU.png](img/CPU_10_load.png) + +В тоже время от увеличения потоков свыше 4-х прироста производительности не отмечается. +Так же результаты тестирования сильно отличаются от прогона к прогону, но динамика того, что прироста на числе потоков > 10 нет остаётся верна. \ No newline at end of file diff --git a/urls.txt b/urls.txt new file mode 100644 index 0000000..cd828f9 --- /dev/null +++ b/urls.txt @@ -0,0 +1,125 @@ +http://fotoinform.net/news/News/Na_stancii_Odessa-Sortirovochnajа_sostojаlis__torzhestva_po_sluchayu_Mezhdunarodnogo_dnjа_pozhil.html +http://www.uz.gov.ua/press_center/latest_news/archive/regional_news/page-12/206799/ +http://fcesteghlal.ir +http://www.the-afc.com/uploads/afc/files/afc_club_rankings_26112015.pdf +http://www.iffhs.de/club-world-ranking-2014/ +https://int.soccerway.com/teams/iran/esteghlal/1164/ +https://int.soccerway.com/players/milad-bagheri/617007/ +https://int.soccerway.com/players/siavash-yazdani/316577/ +https://int.soccerway.com/players/ali-dashti/429136/ +https://int.soccerway.com/players/arash-rezavand/323739/ +https://int.soccerway.com/players/masoud-rigi/218762/ +https://www.instagram.com/p/B0OB7RKgDbH/ +https://www.varzesh3.com/news/1618034/%D9%82%D8%B1%D8%A7%D8%B1%D8%AF%D8%A7%D8%AF-%D9%85%D9%87%D8%AF%DB%8C-%D8%B1%D8%AD%D9%85%D8%AA%DB%8C-%D8%A8%D8%A7-%D9%BE%D8%AF%DB%8C%D8%AF%D9%87-%D8%B1%D8%B3%D9%85%DB%8C-%D8%B4%D8%AFقرارداد +https://www.varzesh3.com/news/1619971/%D8%B1%D8%B3%D9%85%DB%8C-%D9%85%D8%AD%D9%85%D8%AF%DB%8C-%D9%85%D9%87%D8%B1-%D8%A8%D9%87-%D9%BE%D8%AF%DB%8C%D8%AF%D9%87-%D9%BE%DB%8C%D9%88%D8%B3%D8%AA +https://www.varzesh3.com/news/1620179/%D9%85%D8%AF%D8%A7%D9%81%D8%B9-%D8%A7%D8%B3%D8%AA%D9%82%D9%84%D8%A7%D9%84-%D8%A8%D9%87-%D8%AA%D8%B1%D8%A7%DA%A9%D8%AA%D9%88%D8%B1-%D9%BE%DB%8C%D9%88%D8%B3%D8%AA +https://int.soccerway.com/teams/iran/esteghlal/1164/transfers/ +https://www.transfermarkt.com/jaber-ansari/profil/spieler/188116 +https://int.soccerway.com/players/reza-karimi/410754/ +https://int.soccerway.com/players/shahin-taherkhani/409283/ +https://web.archive.org/web/20110628040957/http://www.fcesteghlal.ir/ +https://instagram.com/esteghlal.fc.official/ +https://www.footballdatabase.eu/en/club/team/764 +https://id.loc.gov/authorities/n2010217575 +https://viaf.org/viaf/167814916 +https://www.worldcat.org/identities/containsVIAFID/167814916 +https://www.gcoins.net/ru/catalog/view/1393 +https://www.rma.org.bt/coinsincirculation.jsp +https://www.rma.org.bt/history.jsp +https://www.openstreetmap.org/?mlat=54.80083&mlon=25.88250&zoom=17 +https://www.openstreetmap.org/?mlat=54.80083&mlon=25.88250&zoom=17 +http://globus.tut.by/bystrica/kostel493_a80.jpg +http://orda.of.by/.lib/spik/gr/86?m=68.1,8.8 +http://orda.of.by/.add/gallery.php?bystrica/kostel/art/mh +http://catholic.by/2/belarus/dioceses/grodnensis/100674.html +http://globus.tut.by/bystrica/index.htm +https://web.archive.org/web/20150826040954/http://globus.tut.by/bystrica/index.htm +http://orda.of.by/.lib/abes/96 +http://catholic.by/2/belarus/dioceses/grodnensis/100674.html +http://globus.tut.by/bystrica/index.htm#kostel +http://web.archive.org/web/20150826040954/http://globus.tut.by/bystrica/index.htm#kostel +http://radzima.org/be/object/1399.html +https://www.openstreetmap.org/?mlat=45.98944&mlon=10.34278&zoom=12 +https://www.openstreetmap.org/?mlat=45.98944&mlon=10.34278&zoom=12 +http://www.comune.braone.bs.it/ +http://www.comune.braone.bs.it/ +http://www.comune.braone.bs.it/ +http://www.istat.it/ +http://www.istat.it/english/ +http://web.archive.org/web/20091207102304/http://www.istat.it/english/ +https://www.openstreetmap.org/?mlat=56.178082&mlon=50.630361&zoom=14 +https://www.openstreetmap.org/?mlat=56.178082&mlon=50.630361&zoom=14 +https://classinform.ru/okato/search.php?str=92233000026 +https://classinform.ru/oktmo/search.php?str=92633423101 +https://tatarica.org/ru/razdely/municipalnye-obrazovaniya/municipalnye-rajony/kukmorskij-rajon-1/kaensar +https://toponym.antat.ru/toponym/2496 +https://www.openstreetmap.org/?mlat=43.000529&mlon=41.024891&zoom=14 +https://cyberleninka.ru/article/n/ekspozitsiya-hudozhestvennoy-vystavki-kak-sposob-vospitaniya-i-hudozhestvennogo-obrazovaniya-na-primere-vystavok-v-respublike-abhaziya +http://abkhazinform.com/item/5685-v-tsentralnom-vystavochnom-zale-soyuza-khudozhnikov-abkhazii-otkrylas-vesennyaya-vystavka +https://cyberleninka.ru/article/n/ekspozitsiya-hudozhestvennoy-vystavki-kak-sposob-vospitaniya-i-hudozhestvennogo-obrazovaniya-na-primere-vystavok-v-respublike-abhaziya +https://www.ekhokavkaza.com/a/31250046.html +https://bronzaikamen.ru/novosti/centralnyj-vystavochnyj-zal-soyuza-xudozhnikov-abxazii/ +http://abkhazinform.com/item/5280-v-sukhume-posle-kapitalnogo-remonta-otkrylsya-tsentralyj-vystavochnyj-zal-soyuza-khudozhnikov-abkhazii +https://www.ekhokavkaza.com/a/25253176.html +https://www.ekhokavkaza.com/a/28918534.html +https://www.ekhokavkaza.com/a/29304903.html +http://www.uboat.net/men/emmermann.htm +http://www.pravenc.ru/text/154123.html +http://www.vostlit.info/Texts/rus9/Smbat_Sparapet/vved2.phtml?id=2178 +https://books.google.de/books?id=q4hb_948o1AC +https://www.genealogics.org/getperson.php?personID=I00155536&tree=LEO +https://www.treccani.it/enciclopedia/charles-ii-de-cosse-conte-poi-duca-di-brissac +http://catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id=XX5614784 +https://catalogue.bnf.fr/ark:/12148/cb13009204p +https://d-nb.info/gnd/1055262865 +http://isni-url.oclc.nl/isni/0000000362566598 +https://data.bibliotheken.nl/id/thes/p157219860 +https://www.idref.fr/080681727 +https://viaf.org/viaf/226736329 +https://www.worldcat.org/identities/containsVIAFID/226736329 +https://www.openstreetmap.org/?mlat=52.43333&mlon=20.68333&zoom=11 +https://www.openstreetmap.org/?mlat=52.43333&mlon=20.68333&zoom=11 +http://www.regioset.pl/p.nowodworski.maz +http://stat.gov.pl/download/gfx/portalinformacyjny/pl/defaultaktualnosci/5468/6/12/1/lu_ludnosc_stan_struktura_31-12-2013.pdf +https://web.archive.org/web/20141006221028/http://stat.gov.pl/download/gfx/portalinformacyjny/pl/defaultaktualnosci/5468/6/12/1/lu_ludnosc_stan_struktura_31-12-2013.pdf +http://www.regioset.pl/p.nowodworski.maz +http://shieldandsword.mozohin.ru/VD3462/terr_org/oblast/vladimir.htm +http://avo.ru/-/dolgov-vladimir-vasil-evic +https://www.openstreetmap.org/?mlat=47.29694&mlon=7.77083&zoom=12 +https://www.openstreetmap.org/?mlat=47.29694&mlon=7.77083&zoom=12 +http://www.niederbuchsiten.ch +http://www.niederbuchsiten.ch +http://www.niederbuchsiten.ch/gemeinde/gemeinderat.html +https://web.archive.org/web/20110707002117/http://www.niederbuchsiten.ch/gemeinde/gemeinderat.html +http://www.frankklepacki.com/ +https://www.facebook.com/note.php?note_id=119522869602 +https://youtube.com/watch?v=LdilAkqMEbE +http://www.theconnextion.com/index.cfm?ArtistID=72&NoFrame=Yes +https://web.archive.org/web/20071025021929/http://www.theconnextion.com/index.cfm?ArtistID=72&NoFrame=Yes +http://www.frankklepacki.com/ +https://web.archive.org/web/20071025021929/http://www.theconnextion.com/index.cfm?ArtistID=72&NoFrame=Yes +https://www.discogs.com/artist/3740714 +https://musicbrainz.org/artist/cf22b8b7-b5a5-4a16-b201-4d5e8ef22ffc +https://ssd.jpl.nasa.gov/sbdb.cgi?sstr=2000896 +https://newton.spacedys.com//astdys/index.php +https://books.google.ru/books?id=aeAg1X7afOoC&pg=PA77&redir_esc=y#v=onepage&q&f=false +https://sbntools.psi.edu/ferret/SimpleSearch/results.action?targetName=896+Sphinx +http://www.minorplanet.info/PHP/generateOneAsteroidInfo.php?AstInfo=896 +https://arxiv.org/abs/1807.02083 +https://dx.doi.org/10.1051%2F0004-6361%2F201833437 +https://arxiv.org/abs/1406.6645 +https://dx.doi.org/10.1088%2F0004-637X%2F791%2F2%2F121 +https://watermark.silverchair.com/pasj63-1117.pdf?token=AQECAHi208BE49Ooan9kkhW_Ercy7Dm3ZL_9Cf3qfKAc485ysgAAAmEwggJdBgkqhkiG9w0BBwagggJOMIICSgIBADCCAkMGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMAfbU2-YmhW7BTEYIAgEQgIICFEBZV_RlUw465purk4qr4pgLR34j9ZAND6POeSwu2JVvk_MyjSWW-tADmQT7C4PSyTDZ2-0f4IN-rkRtRIKcKRZJc5qERWg2ge4uPv5vkGsl5x_iweGGcHjt0jXYe7WMUdwhpgi3YC-TKPNwpQ3FnHsoIyEGdiKfMUwc-lAGDYyGH_riJ-g6WigAO0u9-QKnZud2kEBOmvEFgtVDLsWy2uOOMtCk1zDwtJsshrYqjqYBCWfMXxEZL3gOHNw1MRpzXj-oUoSAbhCZfJ9dIZpc6tymYT5cNT0obULp6azH8PD_CxZ5GV1RP2nbxUKXqVX-71UPQPqwK9MCGI4gc45mjZ2ffw-EGRMADj6RhGjEL2bvPoTj6nkkSW2L4BKLub4RhHUBoOxy2rqRt081Hw4eWp1-rxYUWPZ22LFLdRiMvalXekgdrUYEXf3CifbiLhV9yepDVjz953E0CLNt_RqZI45pbbCPTVTBAHioYgjTkDKR_hzXxv4fRCJzj67wEmcUQGml-dPE0srdLSHN4GTn9Wr7ptam91QOmzNYHYTCaTjVg101mnucdhTDkNL-SKU9RXotoNSLjizCME-cXhxabdzM8ZVvyeC3xf6jG6rwfpgCWBG4OTMs_-LDQB6vPvrO26Z4kg6Pzb7IL57Dq1WwFSUqqzDGt9QdwmgvpoA-084rdrnvhSsvNUu1SlH0DcncBWyNyFA +http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=896+Sphinx +https://books.google.com/books?id=VoJ5nUyIzCsC +https://ssd.jpl.nasa.gov/sbdb.cgi?sstr=2000896 +https://www.openstreetmap.org/?mlat=54.54333&mlon=-1.92667&zoom=12 +https://www.openstreetmap.org/?mlat=54.54333&mlon=-1.92667&zoom=12 +https://www.english-heritage.org.uk/visit/places/barnard-castle/ +https://web.archive.org/web/20070927021747/http://www.sine.newcastle.ac.uk/view_structure_information.asp?struct_id=21 +http://www.british-history.ac.uk/report.aspx?compid=50779#s1 +https://www.openstreetmap.org/?mlat=54.74750&mlon=32.32500&zoom=12 +https://www.openstreetmap.org/?mlat=54.74750&mlon=32.32500&zoom=12 +https://classinform.ru/okato/search.php?str=66223822015 +https://classinform.ru/oktmo/search.php?str=66623422166 +http://www.admin-smolensk.ru/~websprav/history/raion/book/-Ov-.htm