Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a web application which queries opentsdb server(which in backend using Hbase cluster) for the datapoints of different metrics and using dygraph javascript graphing library, I am plotting those metrics. Since getting all the datapoints of past one day from opentsdb for a particular metric is itself taking nearly 2 seconds, my application which is plotting nearly 25 metrics is becoming very slow.

In order to reduce this latency, I am thinking of using memcached module of php5 for caching all the queries. But I have few questions regarding memcached.

  1. Is there any way I can configure memcache to keep on updating its cache in the background by running some command line queries after particular interval of time.

  2. Is there any way I can configure memcache to always reply for a query using cache instead of first updating its cache because my application just plots datapoints for past one day. Missing out some datapoints is not that critical.

share|improve this question
add comment

1 Answer 1

I think php.net manual for memcached covers your needs. But remember you cannot get the records that you've stored in memcache like you do in your database by select command.

  1. Memcahe is a service that runs in the background and you can connect to it using php's memcache module. Any record that you store in your memcache, has a expire flag which will let your memcache server know when it has to remove your record. Take a look a this.

  2. It should be in your php code, You can add all your records in memcache server and set their expire time to one day for example. All records in memcache are being distinguished by a key. Now in your PHP code, instead of sending a request to your database, at first you can check memcache to know if it's storing your record by sending it your data key, or your data has been removed due to it's expiration. If the record is expired now it's the time to create a query to select data from database and storing it in your memcache server again.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.