summaryrefslogtreecommitdiff
path: root/per-service
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2016-08-08 14:28:26 -0500
committerAndy Doan <andy.doan@linaro.org>2016-08-10 20:04:52 +0000
commit40384a76d99f95d56c2e2d1477da7b8c415f34f7 (patch)
tree7f87fee4dad8b2119293d8a63405d4a833f57c47 /per-service
parentb2e84ac616dd47979e9dd49402a4f7b0d29f2c2f (diff)
downloadansible-playbooks-40384a76d99f95d56c2e2d1477da7b8c415f34f7.tar.gz
gitweb: add caching logic to front page
git.linaro.org has always been terrible slow (and growing) slower rendering the front page. This patch cache's the most resource intensive part of gitweb's front page code path for 90 seconds. Rough testing shows about a 2.5x performance boost. This only runs on public servers to ensure we don't accidentally share private repos Change-Id: I4d27bd103c017b398612e50df467b6f699c9c390 Reviewed-on: https://review.linaro.org/13658 Reviewed-by: Andy Doan <andy.doan@linaro.org>
Diffstat (limited to 'per-service')
-rw-r--r--per-service/git-servers/roles/apache-website/files/gitweb.diff68
-rw-r--r--per-service/git-servers/roles/apache-website/tasks/main.yml4
-rw-r--r--per-service/git-servers/roles/install-deps/tasks/main.yml2
3 files changed, 74 insertions, 0 deletions
diff --git a/per-service/git-servers/roles/apache-website/files/gitweb.diff b/per-service/git-servers/roles/apache-website/files/gitweb.diff
new file mode 100644
index 0000000..2938b1e
--- /dev/null
+++ b/per-service/git-servers/roles/apache-website/files/gitweb.diff
@@ -0,0 +1,68 @@
+diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
+index 33d701d..7040362 100755
+--- a/gitweb/gitweb.perl
++++ b/gitweb/gitweb.perl
+@@ -10,6 +10,7 @@
+ use 5.008;
+ use strict;
+ use warnings;
++use Cache::FileCache;
+ use CGI qw(:standard :escapeHTML -nosticky);
+ use CGI::Util qw(unescape);
+ use CGI::Carp qw(fatalsToBrowser set_message);
+@@ -17,7 +18,8 @@ use Encode;
+ use Fcntl ':mode';
+ use File::Find qw();
+ use File::Basename qw(basename);
+-use Time::HiRes qw(gettimeofday tv_interval);
++use Storable qw(freeze thaw);
++use Time::HiRes qw(gettimeofday time tv_interval);
+ binmode STDOUT, ':utf8';
+
+ if (!defined($CGI::VERSION) || $CGI::VERSION < 4.08) {
+@@ -6445,17 +6447,29 @@ sub git_search_grep_body {
+ ## actions
+
+ sub git_project_list {
++ my $start = time;
+ my $order = $input_params{'order'};
+ if (defined $order && $order !~ m/none|project|descr|owner|age/) {
+ die_error(400, "Unknown order parameter");
+ }
+
+- my @list = git_get_projects_list($project_filter, $strict_export);
++ git_header_html();
++
++ my $cache = Cache::FileCache->new({cache_root => '/tmp/gitweb.cache'});
++ my $cache_key = "projects_$project_filter";
++ my $list = thaw $cache->get($cache_key);
++ my @list;
++ if (not defined $list) {
++ print("<!-- CACHE MISS -->\n");
++ @list = git_get_projects_list($project_filter, $strict_export);
++ } else {
++ print("<!-- CACHE HIT -->\n");
++ @list = @$list;
++ }
+ if (!@list) {
+ die_error(404, "No projects found");
+ }
+
+- git_header_html();
+ if (defined $home_text && -f $home_text) {
+ print "<div class=\"index_include\">\n";
+ insert_file($home_text);
+@@ -6464,7 +6478,13 @@ sub git_project_list {
+
+ git_project_search_form($searchtext, $search_use_regexp);
+ git_project_list_body(\@list, $order);
++ if (not defined $list) {
++ $cache->set($cache_key, freeze(\@list), '90 s');
++ }
+ git_footer_html();
++ open(my $fh, '>>', '/tmp/gitweb.stats') or return;
++ printf $fh "TIME=%f\tCACHE_HIT=%d\tPF=%s\n", (time-$start), defined $list, $project_filter;
++ close $fh;
+ }
+
+ sub git_forks {
diff --git a/per-service/git-servers/roles/apache-website/tasks/main.yml b/per-service/git-servers/roles/apache-website/tasks/main.yml
index 4eed647..680e4cb 100644
--- a/per-service/git-servers/roles/apache-website/tasks/main.yml
+++ b/per-service/git-servers/roles/apache-website/tasks/main.yml
@@ -29,3 +29,7 @@
mode=0444
owner={{ git_user }}
group={{ git_user }}
+
+- name: Apply caching patch to gitweb
+ patch: src=gitweb.diff dest=/usr/share/gitweb/gitweb.cgi backup=yes
+ when: hosttype in ["git-main", "git-slave"] and server_access == "public"
diff --git a/per-service/git-servers/roles/install-deps/tasks/main.yml b/per-service/git-servers/roles/install-deps/tasks/main.yml
index f3494ba..8002381 100644
--- a/per-service/git-servers/roles/install-deps/tasks/main.yml
+++ b/per-service/git-servers/roles/install-deps/tasks/main.yml
@@ -15,6 +15,8 @@
- apache2
- git
- gitweb
+ - libclass-std-storable-perl
+ - libcache-cache-perl
- ntp
- python-requests
- acl