안녕하세요!
플러그인을 설치한 후 서버의 CPU 사용률이 50%에서 90%로 상승했습니다.
저는 Ruby on Rails/PostgreSQL 초보입니다. 플러그인 설정이 CPU 사용률 급증을 유발하는지 궁금합니다. 해당 플러그인은 포인트 시스템 플러그인일 뿐입니다.
플러그인 링크는 다음과 같습니다.
누군가 데이터베이스 구조, 읽기/쓰기 빈도, 메시지 버스 사용이 적절한지 확인해 주시면 감사하겠습니다.
필요하다면 최적화를 위해 비용을 지불할 수 있습니다.
이 정도면 discourse를 실행하기에 충분할 것 같습니다. CPU 사용량이 50%에서 90%까지 변동되는 것은 다소 비정상적으로 보입니다.
플러그인을 확인해 주실 수 있을까요?
주제/게시물/좋아요가 생성될 때마다 UserPoint.create와 MessageBus.publish가 실행되는 것 같습니다.
on(:notification_created) do |notification|
data = JSON.parse(notification.data).with_indifferent_access
badge = Badge.find(data[:badge_id]) if notification.notification_type == Notification.types[:granted_badge]
if badge && badge.badge_grouping_id == 6
user_badge = UserBadge.where(user_id: notification.user_id, badge_id: data[:badge_id]).order(created_at: :desc).first
points = 0
if badge.badge_type_id == BadgeType::Bronze
points = SiteSetting.discourse_rewards_points_for_bronze_badges.to_i
elsif badge.badge_type_id == BadgeType::Silver
points = SiteSetting.discourse_rewards_points_for_silver_badges.to_i
elsif badge.badge_type_id == BadgeType::Gold
points = SiteSetting.discourse_rewards_points_for_gold_badges.to_i
end
description = {
type: 'badge',
badge_id: badge.id,
name: badge.name
}
DiscourseRewards::UserPoint.create(user_id: notification.user_id, user_points_category_id: 1, user_badge_id: user_badge.id, reward_points: points, description: description.to_json) if points > 0
user_message = {
available_points: user_badge.user.available_points
}
MessageBus.publish("/u/#{user_badge.user.id}/rewards", user_message)
end
end
on(:post_created) do |post|
if post.user_id > 0 && post.post_number > 1 && post.topic.archetype != Archetype.private_message
top_posts = Post.where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)
.where(user_id: post.user_id)
.where("post_number > 1")
.order(:created_at)
.limit(SiteSetting.discourse_rewards_daily_top_replies_to_grant_points.to_i)
.pluck(:id) if SiteSetting.discourse_rewards_daily_top_replies_to_grant_points.to_i > 0
if !top_posts || top_posts.include?(post.id)
points = SiteSetting.discourse_rewards_points_for_post_create.to_i
user = User.find(post.user_id)
description = {
type: 'post',
post_id: post.id,
post_number: post.post_number,
topic_slug: post.topic.slug,
topic_id: post.topic.id,
topic_title: post.topic.title
}
DiscourseRewards::UserPoint.create(user_id: post.user_id, user_points_category_id: 4, reward_points: points, description: description.to_json) if points > 0
user_message = {
available_points: post.user.available_points,
points: post.user.total_earned_points
}
MessageBus.publish("/u/#{post.user_id}/rewards", user_message)
end
end
end
on(:topic_created) do |topic|
if topic.user_id > 0 && topic.archetype != Archetype.private_message
top_topics = Topic.where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)
.where(user_id: topic.user_id)
.order(:created_at)
.limit(SiteSetting.discourse_rewards_daily_top_topics_to_grant_points.to_i)
.pluck(:id) if SiteSetting.discourse_rewards_daily_top_topics_to_grant_points.to_i > 0
if !top_topics || top_topics.include?(topic.id)
points = topic.category.custom_fields['rewards_points_for_topic_create'].to_i
points = SiteSetting.discourse_rewards_points_for_topic_create.to_i if points <= 0
user = User.find(topic.user_id)
description = {
type: 'topic',
post_number: 1,
topic_slug: topic.slug,
topic_id: topic.id,
topic_title: topic.title
}
DiscourseRewards::UserPoint.create(user_id: topic.user_id, user_points_category_id: 4, reward_points: points, description: description.to_json) if points > 0
user_message = {
available_points: topic.user.available_points
}
MessageBus.publish("/u/#{topic.user_id}/rewards", user_message)
end
end
end
on(:like_created) do |like|
points = SiteSetting.discourse_rewards_points_for_like_received.to_i
post = Post.find(like.post_id)
user = post.user
if user.id > 0
top_likes = PostAction.where(post_action_type_id: PostActionType.types[:like])
.where(post_id: Post.where(user_id: user.id), created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)
.order(:created_at)
.limit(SiteSetting.discourse_rewards_daily_top_like_received_to_grant_points.to_i)
.pluck(:id) if SiteSetting.discourse_rewards_daily_top_like_received_to_grant_points.to_i > 0
if !top_likes || top_likes.include?(like.id)
description = {
type: 'like',
post_id: post.id,
post_number: post.post_number,
topic_id: post.topic.id,
topic_slug: post.topic.slug,
topic_title: post.topic.title
}
DiscourseRewards::UserPoint.create(user_id: user.id, user_points_category_id: 4, reward_points: points, description: description.to_json) if points > 0
user_message = {
available_points: user.available_points
}
MessageBus.publish("/u/#{user.id}/rewards", user_message)
end
end
end