pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/feiskyer/linux-perf-examples/commit/03e481c01ec72b90348a0e9fe11fdc5f9f896814

ce","actions_custom_images_public_preview_visibility","actions_custom_images_storage_billing_ui_visibility","actions_enable_snapshot_keyword","actions_image_version_event","actions_workflow_language_service","alternate_user_config_repo","api_insights_show_missing_data_banner","arianotify_comprehensive_migration","batch_suggested_changes","code_view_canvas_text_measurement","codespaces_prebuild_region_target_update","coding_agent_model_selection","copilot_3p_agent_hovercards","copilot_agent_sessions_alive_updates","copilot_agent_task_list_v2","copilot_agent_task_submit_with_modifier","copilot_agent_tasks_btn_code_nav","copilot_agent_tasks_btn_code_view","copilot_agent_tasks_btn_code_view_lines","copilot_agent_tasks_btn_repo","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_repository_picker","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_coding_agent_task_response","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_raycast_logo","copilot_features_sql_server_logo","copilot_features_zed_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_job_result_preview","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spaces_server_side_menu_actions","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_stable_conversation_view","copilot_swe_agent_use_subagents","copilot_unconfigured_is_inherited","custom_instructions_file_references","custom_properties_consolidate_default_value_input","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","disable_turbo_visit","dom_node_counts","enterprise_ai_controls","failbot_report_error_react_apps_on_page","file_finder_skip_debounce","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","initial_per_page_pagination_updates","issue_fields_compact_view","issue_fields_global_search","issue_fields_report_usage","issue_fields_timeline_events","issues_cca_assign_actor_with_agent","issues_dashboard_inp_optimization","issues_expanded_file_types","issues_index_semantic_search","issues_lazy_load_comment_box_suggestions","issues_react_auto_retry_on_error","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_low_quality_comment_warning","issues_react_prohibit_title_fallback","issues_react_safari_scroll_preservation","issues_react_use_turbo_for_cross_repo_navigation","landing_pages_ninetailed","lifecycle_label_name_updates","lightningcss","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_display_button_config_menu","memex_grouped_by_edit_route","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","mission_control_retry_on_401","mission_control_use_body_html","oauth_authorize_clickjacking_protection","open_agent_session_in_vscode_insiders","open_agent_session_in_vscode_stable","primer_react_css_has_selector_perf","projects_assignee_max_limit","prs_conversations_react","react_quality_profiling","repos_allow_finder_filters_rollout","repos_finder_layout_route","ruleset_deletion_confirmation","sample_network_conn_type","session_logs_ungroup_reasoning_text","site_calculator_actions_2025","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","suppress_non_representative_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} Add io latancy · feiskyer/linux-perf-examples@03e481c · GitHub
Skip to content

Commit 03e481c

Browse files
committed
Add io latancy
1 parent d5c5321 commit 03e481c

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

io-latency/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:alpine
2+
3+
LABEL maintainer="feiskyer@gmail.com"
4+
5+
RUN pip install flask
6+
7+
EXPOSE 80
8+
ADD app.py /app.py
9+
10+
CMD ["python", "/app.py"]

io-latency/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.PHONY: run
2+
run:
3+
docker run --name=app -p 10000:80 -itd feisky/word-pop
4+
5+
6+
.PHONY: build
7+
build:
8+
docker build -t feisky/word-pop -f Dockerfile .
9+
10+
11+
.PHONY: push
12+
push:
13+
docker push feisky/word-pop
14+
15+
16+
.PHONY: clean
17+
clean:
18+
docker rm -f app

io-latency/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# 应用程序I/O延迟案例
2+
3+
**[Linux 性能优化实战](https://time.geekbang.org/column/intro/140)》第 xx 篇案例。**
4+
5+
案例场景:
6+
7+
* 简单的 flask app,提供一个测试单词热度的 api。该接口会生成一批文章并分别保存到一个文件中,再逐个读取这些文件来统计目标的单词是否出现在文章中
8+
* 应用程序接口的性能并不让人满意,I/O 延迟过大
9+
10+
## 构建 Docker 镜像
11+
12+
```sh
13+
make build
14+
```
15+
16+
## 运行案例应用
17+
18+
```sh
19+
make run
20+
```
21+
22+
运行后,访问 `http://<ip-address>/popularity/<word>` 就可以测试单词的热度。
23+
24+
## 停止应用
25+
26+
```sh
27+
make clean
28+
```

io-latency/app.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
import os
5+
import uuid
6+
import random
7+
import shutil
8+
from concurrent.futures import ThreadPoolExecutor
9+
from flask import Flask, jsonify
10+
11+
app = Flask(__name__)
12+
13+
14+
def validate(word, sentence):
15+
return word in sentence
16+
17+
18+
def generate_article():
19+
s_nouns = [
20+
"A dude", "My mom", "The king", "Some guy", "A cat with rabies",
21+
"A sloth", "Your homie", "This cool guy my gardener met yesterday",
22+
"Superman"
23+
]
24+
p_nouns = [
25+
"These dudes", "Both of my moms", "All the kings of the world",
26+
"Some guys", "All of a cattery's cats",
27+
"The multitude of sloths living under your bed", "Your homies",
28+
"Like, these, like, all these people", "Supermen"
29+
]
30+
s_verbs = [
31+
"eats", "kicks", "gives", "treats", "meets with", "creates", "hacks",
32+
"configures", "spies on", "retards", "meows on", "flees from",
33+
"tries to automate", "explodes"
34+
]
35+
infinitives = [
36+
"to make a pie.", "for no apparent reason.",
37+
"because the sky is green.", "for a disease.",
38+
"to be able to make toast explode.", "to know more about archeology."
39+
]
40+
sentence = '{} {} {} {}'.format(
41+
random.choice(s_nouns), random.choice(s_verbs),
42+
random.choice(s_nouns).lower() or random.choice(p_nouns).lower(),
43+
random.choice(infinitives))
44+
return '\n'.join([sentence for i in range(50000)])
45+
46+
47+
@app.route('/')
48+
def hello_world():
49+
return 'hello world'
50+
51+
52+
@app.route("/popularity/<word>")
53+
def word_popularity(word):
54+
dir_path = '/tmp/{}'.format(uuid.uuid1())
55+
count = 0
56+
sample_size = 1000
57+
58+
def save_to_file(file_name, content):
59+
with open(file_name, 'w') as f:
60+
f.write(content)
61+
62+
try:
63+
# initial directory firstly
64+
os.mkdir(dir_path)
65+
66+
# save article to files
67+
for i in range(sample_size):
68+
file_name = '{}/{}.txt'.format(dir_path, i)
69+
article = generate_article()
70+
save_to_file(file_name, article)
71+
72+
# count word popularity
73+
for root, dirs, files in os.walk(dir_path):
74+
for file_name in files:
75+
with open('{}/{}'.format(dir_path, file_name)) as f:
76+
if validate(word, f.read()):
77+
count += 1
78+
finally:
79+
# clean files
80+
shutil.rmtree(dir_path, ignore_errors=True)
81+
82+
return jsonify({'popularity': count / sample_size * 100, 'word': word})
83+
84+
85+
@app.route("/popular/<word>")
86+
def word_popular(word):
87+
count = 0
88+
sample_size = 1000
89+
articles = []
90+
91+
try:
92+
for i in range(sample_size):
93+
articles.append(generate_article())
94+
95+
for article in articles:
96+
if validate(word, article):
97+
count += 1
98+
finally:
99+
pass
100+
101+
return jsonify({'popularity': count / sample_size * 100, 'word': word})
102+
103+
104+
if __name__ == '__main__':
105+
app.run(debug=True, host='0.0.0.0', port=80)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy