views:

123

answers:

2

I'm trying to load in predefined email messages to send out -- my question is, should I memcache all the email messages rather than just including the file that contains the variables with the email messages, and only call it once a day or something?

+5  A: 

Memcache is handy for lots of reads in separate processes / requests, are you sending with lots of different processes or in a batch? In the latter case, forget memcache.

A local include is pretty fast, and if you're accessing the file often, your OS will even cache the file for you, effectively reading it from memory. No way to tell without testing, but I'd think the biggest speed gain would be having the file in opcode cache (APC for instance): native format & in memory.

Then again, I would be amazed if the file include is a bottleneck in your code, especially if you're mailing. Be very aware of optimization rule #1: Do not solve non-existent performance problems.

Wrikken
Had never heard of optimization rule #1 - thanks! I'm developing a new system so I'm just trying to prepare for the future, but good to know! -- They're separate requests. Each time someone signs up on our site or we have to send an email.
Kerry
dammit, I was so going to say almost exactly that, especially the last bit. +1 for you
Kris
I always thought the first rule of optimization was that the largest gain possible is the transition from a non-working system to a working system (aka: Premature optimization is the root of all evil)... ;-)
ircmaxell
very well said "Do not solve non-existent performance problems", yeah that should be optimization rule #1
sandeepan
+2  A: 

Well, that's a VERY hard question to answer. There are a lot of variables at stake.

Are there a lot of requests for this data (When I say a lot, I mean more than one or two per second)? Memcache would get a point if that's the case...

Are your drives high performance (SCSI or SAS, RAID 0 or 10)? If so, Files MIGHT get a point.

Do you have a lot of RAM? If so, the OS can cache more file data, so less drive activity would be required for a file.

Do you have a lot of these predefined messages? If so, the index of Memcache might make a difference...

Is your Memcache server ONLY on localhost? If not, Memcache will lose a point for network latency.

The bottom line is this. Unless you're doing a TON of lookups (many per second), either will be just as quick (within reason, under 10 to 20 ms). Personally, unless you're doing more than about 10 EMAIL lookups per second, stick with the file method. It's easier to maintain (you don't have to worry about refreshing Memcache if it needs to restart), and will be easier to debug. Remember: keep it simple...

ircmaxell
Thank you for that -- I am not a Server Admin nor do I setup the servers, so I have no idea about the drives. The RAM is definitely low (2-4 gbs I believe) and it is localhost. I'm going to keep it local for now, and if it becomes a problem, then I'll look more into it, but I have a feeling that other things will sooner cause problems.
Kerry