Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Big cache (my top ten software development practices)

by eyepopslikeamosquito (Archbishop)
on Jul 29, 2022 at 08:52 UTC ( [id://11145842]=note: print w/replies, xml ) Need Help??


in reply to Big cache

I'd like to request some general advice on *local* databases ... So... tips? Conventional wisdom? Pitfalls? What to watch out for? That kind of stuff.

For fun, let's start with my top ten list of general software development practices (adapted from On Coding Standards and Code Reviews):

  • Correctness, simplicity and clarity come first. Avoid unnecessary cleverness.
  • Systems should be designed as a set of cohesive modules as loosely coupled as is reasonably feasible.
  • Minimize exposure of module implementation; provide stable interfaces to protect programs from the details of the implementation (which are likely to change).
  • Design components that can be easily tested in isolation.
  • Add new test cases before you start debugging.
  • Adopt a policy of zero tolerance for warnings and errors.
  • Establish a rational error handling policy and follow it strictly. Handle all errors (e.g. don't ignore error returns). Fail securely.
  • Use least privilege; only run with superuser privilege when you need to.
  • Don't optimize prematurely. Benchmark before you optimize. Comment why you are optimizing.
  • Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

So I'd start by defining your "local database interface" based on your requirements. You could then try an implementation of it using, for example, the excellent suggestions above from the Discipulus. If your interface is well designed, you could further experiment with different implementations of it, based on your requirements. If performance was crucial, for example, you could benchmark alternative implementations of your local database interface using different technologies - comparing the performance of built-in Perl hashes with a SQLite memory-based database and Judy Arrays, for example.

If performance is critical for your application, you might be interested in:

  • Comment on Re: Big cache (my top ten software development practices)

Replies are listed 'Best First'.
Re^2: Big cache
by cavac (Parson) on Aug 02, 2022 at 12:47 UTC

    Use least privilege; only run with superuser privilege when you need to.

    Yes, and also take it with a grain of salt if your OS vendor/distributor/kernel author/Linus Torvalds says that you need to be superuser to do a certain thing.

    For example, by default you need to be root to listen to network ports below 1024, meaning that nearly ALL default network programs on your server need to at least have elevated privileges while starting up (or need some sort of port forwarding stuff thats inflexible, awkward and easy to get wrong). This is especially annoying and potentially dangerous when you are actively developing software (like a webserver or a nameserver).

    I usually run my system with net.ipv4.ip_unprivileged_port_start=0. This way no more root required to run your DIY webserver or nameserver (or to debug them in the IDE).

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
      For example, by default you need to be root to listen to network ports below 1024, meaning that nearly ALL default network programs on your server need to at least have elevated privileges while starting up (or need some sort of port forwarding stuff thats inflexible, awkward and easy to get wrong).

      See below the line.

      This is especially annoying and potentially dangerous when you are actively developing software (like a webserver or a nameserver).

      Right.

      I usually run my system with net.ipv4.ip_unprivileged_port_start=0. This way no more root required to run your DIY webserver or nameserver (or to debug them in the IDE).

      And so, even the least privileged user can run DNS, Mail, Web, FTP, whatever servers. That's not secure.


      Savely starting an unprivileged TCP server on a privileged port (i.e. port < 1024) that entirely runs without root privileges is a solved problem. You need a tiny privileged program that opens the socket, then drops privileges, and finally exec()s the real server that inherits the opened socked filehandle to listen on that handle.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145842]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found