in reply to Re: How to store CODE ref
in thread How to store CODE ref

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.

Replies are listed 'Best First'.
Re: Re: Re: How to store CODE ref
by IlyaM (Parson) on Nov 28, 2001 at 23:03 UTC
    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.

        Sorry, but there is no alternative yet. Either you preload your data before Apache forks or it will be duplicated in all childs. No caching solution can help you share that memory between Apache childs.

        You have to wait for Apache 2.0 with mod_perl 2.0 which use threads.