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
99 changes: 99 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

__pycache__/
*.py[cod]
*$py.class

*.so

.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

*.manifest
*.spec

pip-log.txt
pip-delete-this-directory.txt

htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

*.mo
*.pot

*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

instance/
.webassets-cache

.scrapy

docs/_build/

target/

.ipynb_checkpoints

profile_default/
ipython_config.py

.python-version

__pypackages__/

celerybeat-schedule
celerybeat.pid

*.sage.py

.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

.spyderproject
.spyproject

.ropeproject

/site

.mypy_cache/
.dmypy.json
dmypy.json

.pyre/

.idea
23 changes: 23 additions & 0 deletions 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from hashlib import md5
from random import choice
import concurrent.futures


def generate_coin(c):
while True:
s = "".join([choice("0123456789") for i in range(50)])
h = md5(s.encode('utf8')).hexdigest()
if h.endswith("00000"):
c = "{} {}".format(s, h)
break
return c


def new_generate_coin():
with concurrent.futures.ProcessPoolExecutor(max_workers=61) as executor:
for coin in zip(executor.map(generate_coin, [0 for i in range(5)])):
print(coin)


if __name__ == '__main__':
new_generate_coin()
Empty file added 3
Empty file.
24 changes: 24 additions & 0 deletions 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import concurrent.futures
from urllib.request import Request, urlopen

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

def load_wiki_url(url):
request = Request(
url,
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 9.0; Win65; x64; rv:97.0) Gecko/20105107 Firefox/92.0'},
)
try:
resp = urlopen(request, timeout=5)
code = resp.code
resp.close()
return code
except Exception as e:
return url, e

with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
futures = []
for url in links[:100]:
futures.append(executor.submit(load_wiki_url, url))
for future in concurrent.futures.as_completed(futures):
print(future.result())
Empty file added 5
Empty file.
18 changes: 18 additions & 0 deletions 6
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)
Empty file added res.txt
Empty file.
43 changes: 43 additions & 0 deletions отчет.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Отчет
## Задача IO Bound
### Синхронный проход по 100 ссылкам
![](pics/io_1.png)
### Ассинхронный проход по 100 ссылкам

* 5 воркеров
![](pics/io_2.png)
![](pics/io_async_5_disp.png)

* 50 воркевор
![](pics/io_3.png)
![](pics/io_async_50_disp.png)

* 100 воркеров
![](pics/io_4.png)
![](pics/io_async_100_disp.png)

На скринах заметна зависимость производительности программы от количества потоков: чем больше потоков-
тем быстрее программа.

## Задача CPU Bound
### Синхронный поиск одной монеты
![](pics/cpu_1.png)
![](pics/cpu_sync_disp.png)

### Асинхронный поиск 3 монет
* 2 воркера
![](pics/cpu_2.png)
![](pics/cpu_async_2_disp.png)

* 4 воркера
![](pics/cpu_4.png)
![](pics/cpu_async_4_disp.png)

* 61 воркер
![](pics/cpu_5.png)
![](pics/cpu_async_5_disp.png)

С увеличением количества процессов, скорость работы программы тоже увеличивается.
Но скорость программы также зависит от количества логических ядер компьютера, если количество
процессов будет их превышать, то это несущественно скажется на производительности программы или даже
снизит ее.