简体   繁体   中英

Why does my perl script take so long to start up?

After imports the first line I have is a print, but it takes probably 10 seconds for this line to print. I'm pretty sure use Bio::EnsEMBL::Registry; is the culprit here, as I can take away all the hard coded references and it stil loads slowly (the rest are pretty standard imports.

use strict;
use warnings;
use lib "$ENV{HOME}/Ensembl/src/bioperl-1.6.1";
use lib "$ENV{HOME}/Ensembl/src/ensembl/modules";
use lib "$ENV{HOME}/Ensembl/src/ensembl-compara/modules";
use lib "$ENV{HOME}/Ensembl/src/ensembl-variation/modules";
use lib "$ENV{HOME}/Ensembl/src/ensembl-funcgen/modules";
use Bio::EnsEMBL::Registry;
use Data::Dumper;
use Switch;
use DBI;

#****CONNECT TO ENSEMBL****
print"Establishing connection...";

Is there anything I can do to speed up the time it takes to run this script? Thakns

The answer probably depends on what comes after print"Establishing connection..."; If there is a network connection involved, that might explain the lag.

Also, you do not have a newline ( "\\n" ) at the end of the message, therefore, it may be buffered, and the time it appears on your screen may not correspond to the time it takes to reach the statement.

Therefore, you need to actually time how long it takes for the use Bio::EnsEMBL::Registry; line to be completed, and how long it takes for the "establishing connection" parts to be completed.

This is where the $^T variable comes in handy (see perldoc -v '$^T' ):

use strict;
use warnings;
use lib "$ENV{HOME}/Ensembl/src/bioperl-1.6.1";
use lib "$ENV{HOME}/Ensembl/src/ensembl/modules";
use lib "$ENV{HOME}/Ensembl/src/ensembl-compara/modules";
use lib "$ENV{HOME}/Ensembl/src/ensembl-variation/modules";
use lib "$ENV{HOME}/Ensembl/src/ensembl-funcgen/modules";
use Bio::EnsEMBL::Registry;

BEGIN { printf "Loaded 'Bio::EnsEMBL::Registry': [%d] seconds\n", time - $^T };

use Data::Dumper;
use Switch;
use DBI;

#****CONNECT TO ENSEMBL****

printf "Establishing connection ... [%d] seconds\n", time - $^T;

Of course, it may also be useful to switch to a decent logging system .

If it really is the database connection taking a long time, the first thing you should check is if DNS is involved.

Check the contents of the environment variable ENSEMBL_REGISTRY and the file /usr/local/share/ensembl_registry.conf – they can specify databases to connect to and download the addresses of other databases.

  • You might check your DNS settings to make sure your resolvers answer the names quickly
  • You might try disabling IPv6 on your host: If it isn't routing, and one of those DNS servers responds with an IPv6 address, then you will have a delay while IPv6 fails over to the IPv4 addresses.
  • You might try making a local registry (so you don't have to go over the Internet)
  • You might try a smaller "test" registry (so that less data is loaded)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM