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
131 changes: 131 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.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

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

.idea
23 changes: 23 additions & 0 deletions coins.py
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()
11 changes: 11 additions & 0 deletions coins_old.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from hashlib import md5
from random import choice

lst = []
while len(lst) < 5:
s = "".join([choice("0123456789") for i in range(50)])
h = md5(s.encode('utf8')).hexdigest()
if h.endswith("00000"):
lst.append("{} {}".format(s, h))
print(lst)

27 changes: 27 additions & 0 deletions new_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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())

17 changes: 17 additions & 0 deletions old_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from urllib.request import Request, urlopen
from urllib.parse import unquote

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

for url in links[:100]:
try:
request = Request(
url,
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 9.0; Win65; x64; rv:97.0) Gecko/20105107 Firefox/92.0'},
)
resp = urlopen(request, timeout=5)
code = resp.code
print(code)
resp.close()
except Exception as e:
print(url, e)
Binary file added pics/cpu_1.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 pics/cpu_2.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 pics/cpu_4.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 pics/cpu_5.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 pics/cpu_async_2_disp.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 pics/cpu_async_4_disp.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 pics/cpu_async_5_disp.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 pics/cpu_sync_disp.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 pics/io_1.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 pics/io_2.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 pics/io_3.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 pics/io_4.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 pics/io_async_100_disp.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 pics/io_async_50_disp.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 pics/io_async_5_disp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Отчет
## Задача 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)

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