问题:
在Redmine部署使用后,发现更新事务时速度慢,进行了相关试验,去掉了可能影响速度的插件,仍然很慢。以下为对比试验:
1、包含12个自定义字段的项目,更新用时2136ms,记录如下:
Started PATCH "/issues/3115" for 127.0.0.1 at 2016-07-03 10:58:36 +0800
Processing by IssuesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"QNZR0IqhR6x6Otexs0D0w9b+2fWma/0YfiuOskbmGSQYMLB7lwQZJLB19GqANWSjh/6iubUif4l1X+E6nE8vhQ==", "form_update_triggered_by"=>"", "issue"=>{"project_id"=>"5", "tracker_id"=>"5", "subject"=>"XX项目", "description"=>"XX项目", "status_id"=>"6", "priority_id"=>"4", "custom_field_values"=>{"57"=>"", "50"=>"XX", "53"=>"", "11"=>"", "28"=>"XX", "14"=>"2016-05-18", "34"=>"2016-05-18", "51"=>"2016-07-12", "16"=>"0", "3"=>"2016-05-18", "23"=>"", "52"=>""}, "notes"=>"", "lock_version"=>"0"}, "was_default_status"=>"6", "last_journal_id"=>"", "commit"=>"提交", "next_issue_id"=>"3114", "issue_position"=>"1", "issue_count"=>"150", "id"=>"3115"}
Current user: csl (id=26)
Rendered mailer/_issue.text.erb (15.6ms)
Rendered mailer/issue_edit.text.erb within layouts/mailer (31.2ms)
Rendered mailer/_issue.html.erb (0.0ms)
Rendered mailer/issue_edit.html.erb within layouts/mailer (0.0ms)
Redirected to http://127.0.0.1:8080/issues/3115?issue_count=150&issue_position=1&next_issue_id=3114
Completed 302 Found in 2136ms (ActiveRecord: 115.6ms)
2、包含51个自定义字段的项目,更新用时5745ms,记录如下:
Started PATCH "/issues/3890" for 127.0.0.1 at 2016-07-03 10:57:07 +0800
Processing by IssuesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BdB8/SFFGD0lTT45NVQpA/dqUk/s/NExRrR0/orEDStdNp1WPOBGte8CHeIGIbljpmopA/+1U6BNwBt2UG07ig==", "form_update_triggered_by"=>"", "issue"=>{"status_id"=>"2", "priority_id"=>"2", "assigned_to_id"=>"", "start_date"=>"", "due_date"=>"", "custom_field_values"=>{"57"=>"", "28"=>"XXX", "16"=>"", "21"=>"", "22"=>"", "3"=>"", "23"=>"", "35"=>"", "37"=>"0", "24"=>"", "25"=>"", "26"=>"0", "38"=>"", "39"=>"", "40"=>"", "41"=>"", "42"=>"", "43"=>"", "59"=>""}, "notes"=>"", "lock_version"=>"3"}, "last_journal_id"=>"246", "commit"=>"提交", "prev_issue_id"=>"3904", "next_issue_id"=>"3883", "issue_position"=>"2", "issue_count"=>"15", "id"=>"3890"}
Current user: csl (id=26)
Rendered mailer/_issue.text.erb (31.2ms)
Rendered mailer/issue_edit.text.erb within layouts/mailer (93.6ms)
Rendered mailer/_issue.html.erb (15.6ms)
Rendered mailer/issue_edit.html.erb within layouts/mailer (15.6ms)
Rendered mailer/_issue.text.erb (15.6ms)
Rendered mailer/issue_edit.text.erb within layouts/mailer (31.2ms)
Rendered mailer/_issue.html.erb (0.0ms)
Rendered mailer/issue_edit.html.erb within layouts/mailer (15.6ms)
Redirected to http://127.0.0.1:8080/issues/3890?issue_count=15&issue_position=2&next_issue_id=3883&prev_issue_id=3904
Completed 302 Found in 5745ms (ActiveRecord: 66.8ms)
初步看来,解决办法是减少跟踪标签的自定义字段。
解决方案:
1、删除事务跟踪者,可以明显降低事务提交后的等待周期。因为事务更新需要发送邮件给跟踪者,而这个过程比较耗时。
2、减少自定义字段数。