Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize task 4 #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ latest.dump
/public/packs-test
/node_modules
config/database.yml
/config/newrelic.yml


# Ignore storybook static site generation
storybook-static/
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ gem "jquery-rails", "~> 4.3"
gem "kaminari", "~> 1.1"
gem "libhoney", "~> 1.11"
gem "liquid", "~> 4.0"
gem 'newrelic_rpm'
gem "nokogiri", "~> 1.10"
gem "octokit", "~> 4.13"
gem "omniauth", "~> 1.9"
Expand All @@ -75,6 +76,7 @@ gem "pundit", "~> 2.0"
gem "pusher", "~> 1.3"
gem "pusher-push-notifications", "~> 1.0"
gem "rack-host-redirect", "~> 1.3"
gem 'rack-mini-profiler'
gem "rack-timeout", "~> 0.5"
gem "rails", "~> 5.1.6"
gem "rails-assets-airbrake-js-client", "~> 1.5", source: "https://rails-assets.org"
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,12 @@ GEM
net-smtp (0.5.1)
net-protocol
netrc (0.11.0)
newrelic_rpm (9.17.0)
nio4r (2.7.4)
nokogiri (1.15.7-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.7-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
Expand Down Expand Up @@ -726,6 +729,8 @@ GEM
rack (2.2.11)
rack-host-redirect (1.3.0)
rack
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
rack-protection (2.2.4)
rack
rack-proxy (0.7.7)
Expand Down Expand Up @@ -1011,6 +1016,7 @@ GEM

PLATFORMS
aarch64-linux
x86_64-linux

DEPENDENCIES
actionpack-action_caching (~> 1.2)
Expand Down Expand Up @@ -1081,6 +1087,7 @@ DEPENDENCIES
liquid (~> 4.0)
memory_profiler (~> 0.9)
nakayoshi_fork
newrelic_rpm
nokogiri (~> 1.10)
octokit (~> 4.13)
omniauth (~> 1.9)
Expand All @@ -1098,6 +1105,7 @@ DEPENDENCIES
pusher (~> 1.3)
pusher-push-notifications (~> 1.0)
rack-host-redirect (~> 1.3)
rack-mini-profiler
rack-timeout (~> 0.5)
rails (~> 5.1.6)
rails-assets-airbrake-js-client (~> 1.5)!
Expand Down
Binary file added Screenshot_2025-03-11_14-14-41.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/views/stories/_main_stories_feed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
<% if !user_signed_in? && i == 4 %>
<%= render "stories/sign_in_invitation" %>
<% end %>
<%= render "articles/single_story", story: story %>
<%= cache ['single_story', story], expires_in: 24.hours do %>
<%= render "articles/single_story", story: story %>
<% end %>
<% end %>
<% end %>
<% if @stories.size > 1 %>
Expand Down
41 changes: 41 additions & 0 deletions case-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Case-study оптимизации

ApacheBench:
```
Concurrency Level: 5
Time taken for tests: 47.600 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 15984100 bytes
HTML transferred: 15937400 bytes
Requests per second: 2.10 [#/sec] (mean)
Time per request: 2380.021 [ms] (mean)
Time per request: 476.004 [ms] (mean, across all concurrent requests)
Transfer rate: 327.93 [Kbytes/sec] received

```
В задаче имеется подсказка, что заметное время занимает рендеринг partial-ов single_story.html.erb. Однако я этого не увидела

**rack-mini-profiler** показывает первую загрузку страницы за 7480ms, повторные же в пределах 700ms из-за встроенных кэшей
Наибольшее время (2250ms) `articles/_sidebar.html.erb`

**New Relic**
Web transactions time - 2600ms из них ruby занимает 2008ms.
most time consuming - stories#index
stories#index - 790ms
layouts/application.html.erb - 624ms
single_story.html.erb - 206ms
articles/sidebar.html.erb - 120ms

Я закэшировала single_story, тогда
ApacheBench
```
Requests per second: 7.16 [#/sec] (mean)
Time per request: 698.126 [ms] (mean)
Time per request: 139.625 [ms] (mean, across all concurrent requests)
Transfer rate: 1121.84 [Kbytes/sec] received
```

**rack-mini-profiler** показывает время загрузки 350ms
Время загрузки по **NewRelic** тоже уменьшилось, см скриншот.
Но почему это работает - я не понимаю, ведь single_story не выглядела как основная точка роста.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по идее это на самом деле так, возможно надо побольше/подольше поделать запросов, чтобы это увидеть в NewRelic