We've got an existing system which loads data by doing individual SQL queries for each record read, and caching results. We have multiple processors on our HP/UX system, so we take advantage of this by running multiple copies of our program, but the results are still far too slow.
I'd like to replace the current implementation with a system that keeps all the configuration data in memory: similar to the database server, but more efficient, and simpler.
To avoid wasting RAM, I'd like to keep a single copy of all the configuration data in RAM, and let every process that needs to read from it.
Three approaches suggest themselves to me: some sort of "ramdisk" type approach, SysV style shared-memory, and memory-mapped files. I haven't worked with any of these on HP/UX, so I'm unsure of their relative merits. I know that SysV shared memory and memory-mapped files are available, but don't know if a ramdisk is a possibility. I do remember that ramdisks under Linux are (or were?) a kernel option that the system administrator needed to configure. I don't administrate the target system, and I don't think re-building a kernel configuration for our production system would be welcomed for our project. So a ramdisk may not be an option, unless someone knows how to configure one under HP/UX without a kernel re-build.
As for mmap and shared memory options, both seem to have some overhead that I don't really need. I specifically don't need to do any tricky inter-process communication: I just want a common section of memory that can be read quickly.
Shared memory under perl seems to copy the data: is this true under C? Specifically, can I just write an XS module to search quickly through the shared memory section, extract the values I want, and return them to perl? Is there a CPAN module that I've overlooked which does this sort of thing?
Memory mapping (via the mmap() system call)seems tied to a file, which may or may not be what I want. It seems to require an open() call and a mmap() call for each filehandle: does this imply that only processes that can share filehandles can share memory in this way? Or will open/mmap detect that the file has been mmapped already?
I don't ever need to write changes back to the file: will loading the file as read-only optimize for this, or will I pay the overhead of the unused write functionality anyway?Is it even significant?
Any suggestions or specific details on how shared memory and/or mmap() work would be appreciated.
--
Ytrew Q. Uiop
In reply to How best to optimize shared data by Ytrew
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |