I don't know anything about your exact requirements and what your scripts do. But i have a feeling you are doing a lot of data munching. I assume you tried putting your data in a database like PostgreSQL and implementing the time critical parts in SQL?
Example: For a year now i had some performance problems on my DNS server written in Perl. It had to do with white/blacklisting of domains. Basically, it had to do about a million string matches for every request, plus a few thousand regexp matches. I moved the whole matching algorithm into PostgreSQL. It isn't all that optimized yet, but it runs in a fraction of the time:
CREATE OR REPLACE FUNCTION pagecamel.nameserver_isforcenx(search_domai
+n_name text)
RETURNS boolean
LANGUAGE plpgsql
AS $function$
DECLARE
tempvar boolean := false;
BEGIN
-- Check whitelist (non-regex)
SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc
+enxdomain_whitelist
WHERE is_regex = false AND search_domain_name = doma
+in_match);
IF tempvar = true THEN
-- whitelisted
RETURN FALSE;
END IF;
-- Check whitelist (regex)
SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc
+enxdomain_whitelist
WHERE is_regex = true AND search_domain_name ~* doma
+in_match);
IF tempvar = true THEN
-- whitelisted
RETURN FALSE;
END IF;
-- Check blacklist (non-regex)
SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc
+enxdomain
WHERE is_regex = false AND search_domain_name = doma
+in_match);
IF tempvar = true THEN
-- blacklisted
RETURN TRUE;
END IF;
-- Check blacklist (regex)
SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc
+enxdomain
WHERE is_regex = true AND search_domain_name ~* doma
+in_match);
IF tempvar = true THEN
-- blacklisted
RETURN TRUE;
END IF;
-- Neither, so NOT blacklisted
RETURN false;
END;
$function$;
Perl is quite good in general. But when it comes to handling large amounts of data, no "normal" scripting language comes even close to a modern SQL database engine like PostgreSQL. People on those projects spent the last few decades optimizing every last tenth of a percent of performance.
Yeah, there is probably a way to optimize that function using the WITH() clause and/or having some special type of INDEX on the table that's somehow optimized to handle regular expressions or something.
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.