in reply to How to store CODE ref

If efficiency is the aim surely modperl and putting the code in a module would be a good choice. Once the module is loaded and the code compiled it is ready, willing and able for the duration. Often the major bottleneck is in the overhead of starting the new process for each request, not compiling the actual Perl code itself. Under modperl you start one process, compile once and then use this process to deal with all subsequent requests. The first one is slow then it is Win Win Win.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: How to store CODE ref
by gildir (Pilgrim) on Nov 28, 2001 at 22:44 UTC
    Hmmm, maybe I did not made myself perfectly clean. I do use mod_perl just now, but it has several drawbacks. One such drawback is described in Fast shared data structures.

    In short, the problem is with large, mostly-read data that contains embeded perl code. For example, ePerl templates. For efficiecy reasons they must be pre-compiled. That's perfectly easy so far. But I want to change the templates while server is running. No chance to do this efficiently in Apache one-process-per-request architecture.

    So I come up with an idea to store templates in GDBM. But what about embeded perl here? If I whould store it in source form, it will be terribly slooow, compile it in every HTTP request. If I compile it in every httpd process, it will be terribly large. Now, I must pre-compile perl code and store it in GDBM in pre-compiled form.

    How to do that?

    Ad B::Bytecode. I have checked this module, and it looks good. But I can't fugure out how to use it no a piece of perl source that I have in scalar variable instead of whole perl program. Could anyone please help me with this. Some simple 3-line example would be more that sufficient. Thanks a lot.

      You can store your templates in some file cache or database in source form. On each requiest you should check if cache have been updated (just check timestamp of relevant files). If it have been updated you need to recompile template from cache. If it haven't been updated you can use already compiled templates. This is how HTML::Mason handles its components (as example).
        Still not feasible solution. Most of the templates contain embeded perl code. If I would compile them in every Apache process separatly, I will get size_of_compiled_code*number_of_httpd_processes memory consumption. On a large system (hundreds of httpd processes) even a small size of templates will require much memory, and I have quite a large templates.

        In addition to this, they are user-customizable, so I accept that the size of whole bunch of templates will be considerable, too much to store in-memory.