From a4b5151a821a7a91990a3bff6cd4702e9a645b93 Mon Sep 17 00:00:00 2001 From: Jared Bischof Date: Fri, 10 Jul 2015 16:14:06 -0500 Subject: [PATCH 1/3] Added memcache storage for expensive mysql queries on home page. Expires after 2 hours. --- src/MGRAST/lib/WebPage/Home.pm | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/MGRAST/lib/WebPage/Home.pm b/src/MGRAST/lib/WebPage/Home.pm index c6610911..bfc3182b 100644 --- a/src/MGRAST/lib/WebPage/Home.pm +++ b/src/MGRAST/lib/WebPage/Home.pm @@ -6,6 +6,7 @@ use strict; use warnings; use Conf; +use Cache::Memcached; use Number::Format; 1; @@ -123,8 +124,26 @@ function forward_to_search (e) { $content .= "
"; my $formater = new Number::Format(-thousands_sep => ','); - my $bpcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_bp() / 1000000000000), 2); - my $seqcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_sequences() / 1000000000), 2); + my $memd = new Cache::Memcached {'servers' => $Conf::web_memcache, 'debug' => 0, 'compress_threshold' => 10_000, }; + my $cache_key = "bpcount"; + my $cdata = $memd->get("bpcount"); + my $bpcount = 0; + if($cdata) { + $bpcount = $cdata; + } else { + $bpcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_bp() / 1000000000000), 2); + $memd->set("bpcount", $bpcount, 7200); + } + my $seqcount = 0; + $cdata = $memd->get("seqcount"); + if($cdata) { + $seqcount = $cdata; + } else { + $seqcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_sequences() / 1000000000), 2); + $memd->set("seqcount", $seqcount, 7200); + } + $memd->disconnect_all; + my $jobcount = $formater->format_number($self->app->data_handle('MGRAST')->Job->count_all()); my $publiccount = $formater->format_number($self->app->data_handle('MGRAST')->Job->count_public()); From 52157d303c3cdf5b13cbae6edc51b4d4b66d186f Mon Sep 17 00:00:00 2001 From: Jared Bischof Date: Tue, 14 Jul 2015 12:33:22 -0500 Subject: [PATCH 2/3] Removed memcache storage of mysql query. Instead, we enabled caching in the mysql server. --- src/MGRAST/lib/WebPage/Home.pm | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/MGRAST/lib/WebPage/Home.pm b/src/MGRAST/lib/WebPage/Home.pm index bfc3182b..c6610911 100644 --- a/src/MGRAST/lib/WebPage/Home.pm +++ b/src/MGRAST/lib/WebPage/Home.pm @@ -6,7 +6,6 @@ use strict; use warnings; use Conf; -use Cache::Memcached; use Number::Format; 1; @@ -124,26 +123,8 @@ function forward_to_search (e) { $content .= "
"; my $formater = new Number::Format(-thousands_sep => ','); - my $memd = new Cache::Memcached {'servers' => $Conf::web_memcache, 'debug' => 0, 'compress_threshold' => 10_000, }; - my $cache_key = "bpcount"; - my $cdata = $memd->get("bpcount"); - my $bpcount = 0; - if($cdata) { - $bpcount = $cdata; - } else { - $bpcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_bp() / 1000000000000), 2); - $memd->set("bpcount", $bpcount, 7200); - } - my $seqcount = 0; - $cdata = $memd->get("seqcount"); - if($cdata) { - $seqcount = $cdata; - } else { - $seqcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_sequences() / 1000000000), 2); - $memd->set("seqcount", $seqcount, 7200); - } - $memd->disconnect_all; - + my $bpcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_bp() / 1000000000000), 2); + my $seqcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_sequences() / 1000000000), 2); my $jobcount = $formater->format_number($self->app->data_handle('MGRAST')->Job->count_all()); my $publiccount = $formater->format_number($self->app->data_handle('MGRAST')->Job->count_public()); From d3179aad1dba6593443e8f1f25220497350710b6 Mon Sep 17 00:00:00 2001 From: Jared Bischof Date: Tue, 21 Jul 2015 15:10:31 -0500 Subject: [PATCH 3/3] Adding back memcache storage of these stats to make Home page more robust. --- src/MGRAST/lib/WebPage/Home.pm | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/MGRAST/lib/WebPage/Home.pm b/src/MGRAST/lib/WebPage/Home.pm index c6610911..bfc3182b 100644 --- a/src/MGRAST/lib/WebPage/Home.pm +++ b/src/MGRAST/lib/WebPage/Home.pm @@ -6,6 +6,7 @@ use strict; use warnings; use Conf; +use Cache::Memcached; use Number::Format; 1; @@ -123,8 +124,26 @@ function forward_to_search (e) { $content .= "
"; my $formater = new Number::Format(-thousands_sep => ','); - my $bpcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_bp() / 1000000000000), 2); - my $seqcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_sequences() / 1000000000), 2); + my $memd = new Cache::Memcached {'servers' => $Conf::web_memcache, 'debug' => 0, 'compress_threshold' => 10_000, }; + my $cache_key = "bpcount"; + my $cdata = $memd->get("bpcount"); + my $bpcount = 0; + if($cdata) { + $bpcount = $cdata; + } else { + $bpcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_bp() / 1000000000000), 2); + $memd->set("bpcount", $bpcount, 7200); + } + my $seqcount = 0; + $cdata = $memd->get("seqcount"); + if($cdata) { + $seqcount = $cdata; + } else { + $seqcount = $formater->format_number(($self->app->data_handle('MGRAST')->Job->count_total_sequences() / 1000000000), 2); + $memd->set("seqcount", $seqcount, 7200); + } + $memd->disconnect_all; + my $jobcount = $formater->format_number($self->app->data_handle('MGRAST')->Job->count_all()); my $publiccount = $formater->format_number($self->app->data_handle('MGRAST')->Job->count_public());