Skip to content

Commit 2c03aee

Browse files
committed
added new relic
1 parent 98e2414 commit 2c03aee

File tree

6 files changed

+118
-1
lines changed

6 files changed

+118
-1
lines changed

.dev_to/compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ x-backend: &backend
3333
ALGOLIASEARCH_APPLICATION_ID: ${ALGOLIASEARCH_APPLICATION_ID}
3434
ALGOLIASEARCH_API_KEY: ${ALGOLIASEARCH_API_KEY}
3535
ALGOLIASEARCH_SEARCH_ONLY_KEY: ${ALGOLIASEARCH_SEARCH_ONLY_KEY}
36+
NEW_RELIC_KEY: ${NEW_RELIC_KEY}
37+
SCOUT_KEY: ${SCOUT_KEY}
3638
REDIS_URL: redis://redis:6379/
3739
DATABASE_URL: postgres://postgres:postgres@postgres:5432
3840
WEBPACKER_DEV_SERVER_HOST: webpacker

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ gem "uglifier", "~> 4.1"
104104
gem "validate_url", "~> 1.0"
105105
gem "webpacker", "~> 3.6"
106106
gem "webpush", "~> 0.3"
107+
gem 'newrelic_rpm'
108+
gem 'scout_apm'
109+
gem 'rack-mini-profiler'
107110

108111
group :development do
109112
gem "better_errors", "~> 2.5"

Gemfile.lock

+8
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ GEM
646646
net-smtp (0.5.1)
647647
net-protocol
648648
netrc (0.11.0)
649+
newrelic_rpm (9.17.0)
649650
nio4r (2.7.4)
650651
nokogiri (1.15.7-aarch64-linux)
651652
racc (~> 1.4)
@@ -726,6 +727,8 @@ GEM
726727
rack (2.2.11)
727728
rack-host-redirect (1.3.0)
728729
rack
730+
rack-mini-profiler (3.3.1)
731+
rack (>= 1.2.0)
729732
rack-protection (2.2.4)
730733
rack
731734
rack-proxy (0.7.7)
@@ -877,6 +880,8 @@ GEM
877880
addressable (>= 2.3.5)
878881
faraday (> 0.8, < 2.0)
879882
sax-machine (1.3.2)
883+
scout_apm (5.6.1)
884+
parser
880885
sdoc (1.1.0)
881886
rdoc (>= 5.0)
882887
selectize-rails (0.12.6)
@@ -1081,6 +1086,7 @@ DEPENDENCIES
10811086
liquid (~> 4.0)
10821087
memory_profiler (~> 0.9)
10831088
nakayoshi_fork
1089+
newrelic_rpm
10841090
nokogiri (~> 1.10)
10851091
octokit (~> 4.13)
10861092
omniauth (~> 1.9)
@@ -1098,6 +1104,7 @@ DEPENDENCIES
10981104
pusher (~> 1.3)
10991105
pusher-push-notifications (~> 1.0)
11001106
rack-host-redirect (~> 1.3)
1107+
rack-mini-profiler
11011108
rack-timeout (~> 0.5)
11021109
rails (~> 5.1.6)
11031110
rails-assets-airbrake-js-client (~> 1.5)!
@@ -1118,6 +1125,7 @@ DEPENDENCIES
11181125
s3_direct_upload (~> 0.1)
11191126
sail (~> 1.5)
11201127
sass-rails (~> 5.0)
1128+
scout_apm
11211129
sdoc (~> 1.0)
11221130
selenium-webdriver (~> 3.141)
11231131
serviceworker-rails (~> 0.5)

app/views/stories/_main_stories_feed.html.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
<% if !user_signed_in? && i == 4 %>
5656
<%= render "stories/sign_in_invitation" %>
5757
<% end %>
58-
<%= render "articles/single_story", story: story %>
58+
<% cache ["v1", story, story.updated_at, story.comments_count, story.positive_reactions_count] do %>
59+
<%= render "articles/single_story", story: story %>
60+
<% end %>
5961
<% end %>
6062
<% end %>
6163
<% if @stories.size > 1 %>

case-study.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Задание 4
2+
3+
## Актуальная проблема
4+
В проекте dev.to выявлена проблема производительности главной страницы:
5+
- Медленный рендеринг главной страницы (StoriesController#index) (Особенно затратный рендеринг partial-ов _single_story.html.erb)
6+
- Отсутствие кэширования страниц
7+
8+
## Формирование метрик
9+
Для оценки эффективности оптимизации определены следующие метрики:
10+
11+
- Время полной загрузки главной страницы
12+
- Время рендеринга partial _single_story.html.erb
13+
- Количество запросов к БД при рендеринге страницы
14+
- Использование CPU и памяти
15+
- Включил кеширование на локальном окружении
16+
- Использование `benchmark` с помощью `ab` (`ab -n 100 -c 5 http://localhost:3000/`)
17+
18+
## Feedback-Loop
19+
Построен быстрый цикл обратной связи:
20+
21+
- NewRelic APM для мониторинга метрик
22+
- rack-mini-profiler для профилирования рендеринга
23+
- Поиск точек роста
24+
25+
## Использованы инструменты профилирования:
26+
27+
- NewRelic для анализа узких мест
28+
- rack-mini-profiler для детального профилирования рендеринга
29+
- Логи Rails для анализа SQL-запросов
30+
31+
## Результаты оптимизации:
32+
33+
### 1. Многократный рендеринг partial-ов _single_story.html.erb
34+
- rack-mini-profilier
35+
-
36+

config/newrelic.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# This file configures the New Relic Agent. New Relic monitors Ruby, Java,
3+
# .NET, PHP, Python, Node, and Go applications with deep visibility and low
4+
# overhead. For more information, visit www.newrelic.com.
5+
#
6+
# Generated October 28, 2022
7+
#
8+
# This configuration file is custom generated for NewRelic Administration
9+
#
10+
# For full documentation of agent configuration options, please refer to
11+
# https://docs.newrelic.com/docs/agents/ruby-agent/installation-configuration/ruby-agent-configuration
12+
13+
common: &default_settings
14+
# Required license key associated with your New Relic account.
15+
license_key: <%= ENV['NEW_RELIC_KEY'] %>
16+
17+
# Your application name. Renaming here affects where data displays in New
18+
# Relic. For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications
19+
app_name: 'devto'
20+
21+
distributed_tracing:
22+
enabled: true
23+
24+
# To disable the agent regardless of other settings, uncomment the following:
25+
26+
# agent_enabled: false
27+
28+
# Logging level for log/newrelic_agent.log
29+
log_level: info
30+
31+
application_logging:
32+
# If `true`, all logging-related features for the agent can be enabled or disabled
33+
# independently. If `false`, all logging-related features are disabled.
34+
enabled: true
35+
forwarding:
36+
# If `true`, the agent captures log records emitted by this application.
37+
enabled: true
38+
# Defines the maximum number of log records to buffer in memory at a time.
39+
max_samples_stored: 10000
40+
metrics:
41+
# If `true`, the agent captures metrics related to logging for this application.
42+
enabled: true
43+
local_decorating:
44+
# If `true`, the agent decorates logs with metadata to link to entities, hosts, traces, and spans.
45+
# This requires a log forwarder to send your log files to New Relic.
46+
# This should not be used when forwarding is enabled.
47+
enabled: false
48+
49+
# Environment-specific settings are in this section.
50+
# RAILS_ENV or RACK_ENV (as appropriate) is used to determine the environment.
51+
# If your application has other named environments, configure them here.
52+
development:
53+
<<: *default_settings
54+
app_name: 'devto (Development)'
55+
56+
test:
57+
<<: *default_settings
58+
# It doesn't make sense to report to New Relic from automated test runs.
59+
monitor_mode: false
60+
61+
staging:
62+
<<: *default_settings
63+
app_name: 'devto (Staging)'
64+
65+
production:
66+
<<: *default_settings

0 commit comments

Comments
 (0)