Schrift
[thread]5386[/thread]

speed-up trotz module: ... (Seite 2)



<< |< 1 2 >| >> 18 Einträge, 2 Seiten
Heromaster
 2003-11-12 11:46
#48397 #48397
User since
2003-08-05
220 Artikel
BenutzerIn
[default_avatar]
Vielleicht löst Vererbung von Klassen einen Teil Deiner Probleme?
Code: (dl )
1
2
3
4
5
6
7
8
package Sources::MailCompose;
@ISA = qw( Sources::Global Sources::Session Sources::Config Session::MailShow);
use strict;
use warnings;
use Sources::Mail;
use Sources::Uploader;
use Sources::Mime;
use Sources::SMTP;
Derjenige, der zwei Hasen jagt, lässt einen zurück und verliert den anderen.
Strat
 2003-11-12 13:38
#48398 #48398
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
gab es da nicht ein Modul namens Memoize oder so aehnlich? vielleicht hilft dir das
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
kabel
 2003-11-12 17:50
#48399 #48399
User since
2003-08-04
704 Artikel
BenutzerIn
[default_avatar]
[quote=Strat,12.11.2003, 12:38]gab es da nicht ein Modul namens Memoize oder so aehnlich? vielleicht hilft dir das[/quote]
der hinweis auf CPAN:Memoize ist gut, passt in diesem kontext jedoch nicht (ganz).

Memoize implementiert eine art cache, der bereits berechnete werte einer teueren funktion zwischenspeichert und bei erneutem anfragen direkt antworten kann. ein modul wird genau einmal geladen. :p es sei denn, einer verändert den %INC hash, was schlechten manieren gleichkommt ;)
-- stefan
Strat
 2003-11-12 21:44
#48400 #48400
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
nebenbei: wenn du es in mod_perl umschreibst, kannst du die groesseren Module in der httpd.conf vorladen lassen:
z.B.
Code: (dl )
     PerlRequire f:/apacheweb/8084_develop.perl-community.de/html/cgi-bin/mod_perl_startup.pl

und mod_perl_startup.pl sieht beim forum bisher folgendermaszen aus:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/perl

# care for paths
BEGIN {
   use vars qw($PATH_TO_CGI);
   $PATH_TO_CGI = 'f:\apacheweb\8084_develop.perl-community.de\html\cgi-bin';
   $ENV{PATH_TO_CGI} = 'f:\apacheweb\8084_develop.perl-community.de\html\cgi-bin';
}
use lib "$PATH_TO_CGI";

# load perl modules
use Apache::DBI;
use CGI;
use HTML::Template;
use Mail::RFC822::Address;
use HTML::Entities ();
use Regexp::Common qw(balanced);
use URI::Find::Schemeless ();
# use DBI ();
use Digest::MD5;
use File::Temp;

# load own PBoard-modules
use PBoard::Config;
use PBoard::Config;
use PBoard::Actions;
use PBoard::Subs;
use PBoard::User;
use PBoard::DB;
use PBoard::Posting;

my $dbh = Apache::DBI->connect_on_init
   ('DBI:mysql:' . &PBoard::Config::DATABASE_NAME,
    &PBoard::Config::DATABASE_USER,
    &PBoard::Config::DATABASE_PASSWORD,
    )
   or die "Error: couldn't connect to MySql: ", $DBI->errstr;
1;

der code ist leider noch nicht perfekt, aber er zeigt vielleicht die grundsaetzliche idee: der punkt ist, dass dann die Module fuer alle threads normalerweise nur einmal fuer alle apache-prozesse in den speicher geladen werden, und man so auch RAM spart. die datenbankverbindungen werden (wenn immer mit dem gleichen user verbunden wird) auch so oft wiederverwendet wie moeglich, d.h. es spart einiges an overhead fuer den verbindungsabufbau.

Exporter-Module - soweit moeglich - mit use Modul (); laden, damit 1. der namespace sauber bleibt und weniger RAM benoetigt wird. Bei HTML::Template das caching aktivieren (entweder "normales" caching oder sogar das IPC-Caching).\n\n

<!--EDIT|Strat|1068666376-->
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
esskar
 2003-11-12 21:57
#48401 #48401
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
leider läuft das ding nicht immer auf einem Apache!

caching von HTML::Template!?! Wie und Wann?
Strat
 2003-11-13 00:07
#48402 #48402
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
aus CPAN:HTML::Template
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        *   cache - if set to 1 the module will cache in memory the parsed
templates based on the filename parameter and modification date
of the file. This only applies to templates opened with the
filename parameter specified, not scalarref or arrayref
templates. Caching also looks at the modification times of any
files included using <TMPL_INCLUDE> tags, but again, only if the
template is opened with filename parameter.

This is mainly of use in a persistent environment like
Apache/mod_perl. It has absolutely no benefit in a normal CGI
environment since the script is unloaded from memory after every
request. For a cache that does work for normal CGIs see the
'shared_cache' option below.

Note that different new() parameter settings do not cause a
cache refresh, only a change in the modification time of the
template will trigger a cache refresh. For most usages this is
fine. My simplistic testing shows that using cache yields a 90%
performance increase under mod_perl. Cache defaults to 0.

* shared_cache - if set to 1 the module will store its cache in
shared memory using the IPC::SharedCache module (available from
CPAN). The effect of this will be to maintain a single shared
copy of each parsed template for all instances of HTML::Template
to use. This can be a significant reduction in memory usage in a
multiple server environment. As an example, on one of our
systems we use 4MB of template cache and maintain 25 httpd
processes - shared_cache results in saving almost 100MB! Of
course, some reduction in speed versus normal caching is to be
expected. Another difference between normal caching and
shared_cache is that shared_cache will work in a CGI environment
- normal caching is only useful in a persistent environment like
Apache/mod_perl.

By default HTML::Template uses the IPC key 'TMPL' as a shared
root segment (0x4c504d54 in hex), but this can be changed by
setting the 'ipc_key' new() parameter to another 4-character or
integer key. Other options can be used to affect the shared
memory cache correspond to IPC::SharedCache options - ipc_mode,
ipc_segment_size and ipc_max_size. See IPC::SharedCache for a
description of how these work - in most cases you shouldn't need
to change them from the defaults.

For more information about the shared memory cache system used
by HTML::Template see IPC::SharedCache.

* double_cache - if set to 1 the module will use a combination of
shared_cache and normal cache mode for the best possible
caching. Of course, it also uses the most memory of all the
cache modes. All the same ipc_* options that work with
shared_cache apply to double_cache as well. By default
double_cache is off.

* blind_cache - if set to 1 the module behaves exactly as with
normal caching but does not check to see if the file has changed
on each request. This option should be used with caution, but
could be of use on high-load servers. My tests show blind_cache
performing only 1 to 2 percent faster than cache under mod_perl.

NOTE: Combining this option with shared_cache can result in
stale templates stuck permanently in shared memory!

* file_cache - if set to 1 the module will store its cache in a
file using the Storable module. It uses no additional memory,
and my simplistic testing shows that it yields a 50% performance
advantage. Like shared_cache, it will work in a CGI environment.
Default is 0.

If you set this option you must set the "file_cache_dir" option.
See below for details.

NOTE: Storable using flock() to ensure safe access to cache
files. Using file_cache on a system or filesystem (NFS) without
flock() support is dangerous.
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
Strat
 2003-11-13 00:08
#48403 #48403
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
also wenn es sich um reines cgi handelt, koennte file_cache oder shared_cache was fuer dich sein
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
esskar
 2003-11-13 01:02
#48404 #48404
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
[quote=Strat,12.11.2003, 23:08]also wenn es sich um reines cgi handelt, koennte file_cache oder shared_cache was fuer dich sein[/quote]
aha ja... danke!
<< |< 1 2 >| >> 18 Einträge, 2 Seiten



View all threads created 2003-11-10 01:35.