Change TO monitoring.json to raw SQL This is 3-10x faster, and this endpoint is one of the slowest.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/8942ce09 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/8942ce09 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/8942ce09 Branch: refs/heads/master Commit: 8942ce09e78e0b4e89e02075537ae65434189fc5 Parents: fe90d11 Author: Robert Butts <robert.o.bu...@gmail.com> Authored: Tue Mar 21 15:19:03 2017 -0600 Committer: Dewayne Richardson <dewr...@apache.org> Committed: Wed Mar 22 11:26:46 2017 -0600 ---------------------------------------------------------------------- traffic_ops/app/lib/API/Cdn.pm | 66 ++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8942ce09/traffic_ops/app/lib/API/Cdn.pm ---------------------------------------------------------------------- diff --git a/traffic_ops/app/lib/API/Cdn.pm b/traffic_ops/app/lib/API/Cdn.pm index 93987e5..9fa1fb7 100644 --- a/traffic_ops/app/lib/API/Cdn.pm +++ b/traffic_ops/app/lib/API/Cdn.pm @@ -421,44 +421,34 @@ sub get_traffic_monitor_config { push( @{ $data_obj->{'deliveryServices'} }, $delivery_service ); } - my $rs_caches = $self->db->resultset('Server')->search( - { 'cdn.name' => $cdn_name }, - { - prefetch => [ 'type', 'status', 'cachegroup', 'profile', 'cdn' ], - columns => [ 'host_name', 'domain_name', 'tcp_port', 'interface_name', 'ip_address', 'ip6_address', 'id', 'xmpp_id' ] - } - ); - - while ( my $row = $rs_caches->next ) { - if ( $row->type->name eq "RASCAL" ) { - my $traffic_monitor; - $traffic_monitor->{'hostName'} = $row->host_name; - $traffic_monitor->{'fqdn'} = $row->host_name . "." . $row->domain_name; - $traffic_monitor->{'status'} = $row->status->name; - $traffic_monitor->{'cachegroup'} = $row->cachegroup->name; - $traffic_monitor->{'port'} = int( $row->tcp_port ); - $traffic_monitor->{'ip'} = $row->ip_address; - $traffic_monitor->{'ip6'} = $row->ip6_address; - $traffic_monitor->{'profile'} = $row->profile->name; - push( @{ $data_obj->{'trafficMonitors'} }, $traffic_monitor ); - - } - elsif ( $row->type->name =~ m/^EDGE/ || $row->type->name =~ m/^MID/ ) { - my $traffic_server; - $traffic_server->{'cachegroup'} = $row->cachegroup->name; - $traffic_server->{'hostName'} = $row->host_name; - $traffic_server->{'fqdn'} = $row->host_name . "." . $row->domain_name; - $traffic_server->{'port'} = int( $row->tcp_port ); - $traffic_server->{'interfaceName'} = $row->interface_name; - $traffic_server->{'status'} = $row->status->name; - $traffic_server->{'ip'} = $row->ip_address; - $traffic_server->{'ip6'} = ( $row->ip6_address || "" ); - $traffic_server->{'profile'} = $row->profile->name; - $traffic_server->{'type'} = $row->type->name; - $traffic_server->{'hashId'} = $row->xmpp_id; - push( @{ $data_obj->{'trafficServers'} }, $traffic_server ); - } - + my $caches_query = 'SELECT + me.host_name as hostName, + CONCAT(me.host_name, \'.\', me.domain_name) as fqdn, + status.name as status, + cachegroup.name as cachegroup, + me.tcp_port as port, + me.ip_address as ip, + me.ip6_address as ip6, + profile.name as profile, + me.interface_name as interfaceName, + type.name as type, + me.xmpp_id as hashId + FROM server me + JOIN type type ON type.id = me.type + JOIN status status ON status.id = me.status + JOIN cachegroup cachegroup ON cachegroup.id = me.cachegroup + JOIN profile profile ON profile.id = me.profile + JOIN cdn cdn ON cdn.id = me.cdn_id + WHERE cdn.name = ?;'; + my $dbh = $self->db->storage->dbh; + my $caches_servers = $dbh->selectall_arrayref( $caches_query, {Columns=>{}}, ($cdn_name) ); + foreach (@{ $caches_servers }) { + if ( $_->{'type'} eq "RASCAL" ) { + push( @{ $data_obj->{'trafficMonitors'} }, $_ ); + } + elsif ( $_->{'type'} =~ m/^EDGE/ || $_->{'type'} =~ m/^MID/ ) { + push( @{ $data_obj->{'trafficServers'} }, $_ ); + } } my $rs_loc = $self->db->resultset('Server')->search(