Optimize Ecstore MongoDB Big Data reading and writing efficiency

Source: Internet
Author: User

Transferred from the co-function BBS

Split table Access KV
<?PHP/*Ecstore MongoDB class base/lib/kvstore/mongodb.php with split optimization*/classBase_kvstore_mongodb extends Base_kvstore_abstract implements Base_interface_kvstore_base {Static Private$_mongodb =NULL; function __construct ($prefix) {$prefix= Is_string ($prefix)? Preg_replace ("(\/|\\|\-|-|-|\_|_)",'.', $prefix): MD5 (Var_export ($prefix,true)); $ This->prefix =$prefix; if(!isset (SELF::$_MONGODB)) {$server= Defined ('Mongodb_server_config')? Mongodb_server_config:"mongodb://localhost:27017"; $option= Defined ('Mongodb_option_config')? Eval (mongodb_opeion_config): Array ("Connect"=TRUE); Self::$_mongodb=NewMongo ($server, $option); }         $ This->mongodb = Self::$_mongodb->selectcollection ('Ecos',$ This-prefix); }//End Function     Publicfunction Fetch ($key, & $value, $timeout _version=NULL) {$store= $ This->mongodb->findone (Array ('Key'=>$ This-Create_key ($key))); if(!is_null ($store) && $timeout _version < $store ['Dateline']){            if($store ['TTL'] >0&& ($store ['Dateline']+ $store ['TTL']) <Time ()) {                return false; } $value= $store ['value']; return true; }        return false; }//End Function     Publicfunction Store ($key, $value, $ttl =0) {$store ['value'] =$value; $store ['Dateline'] =Time (); $store ['TTL'] =$ttl; $store ['Key'] = $ This-Create_key ($key); $store ['prefix'] = $ This-prefix; $res= $ This->mongodb->update (Array ('Key'= = $store ['Key']), $store, Array ("Upsert"=true)); return$res; }//End Function     Publicfunction Delete ($key) {return$ This->mongodb->remove (Array ('Key'=>$ This-Create_key ($key))); }//End Function     Publicfunction Recovery ($record) {$key= $record ['Key']; $store ['Key'] = $ This-Create_key ($key); $store ['value'] = $record ['value']; $store ['Dateline'] = $record ['Dateline']; $store ['TTL'] = $record ['TTL']; $res= $ This->mongodb->update (Array ('Key'= = $store ['Key']), $store, Array ("Upsert"=true)); return$res; }//End Function}//End Class
Ensure the index of each key table

Whenever the amount of MONGODB data explosion, read and write frequently, the lock table is serious, basically is the index is not added, or has not been a table-breaking scheme.

/* MONGO command-line Operations */ Use ecosshow collectionsdb.printcollectionstats () db. default. Ensureindex ({key:1}) Db.b2c.cart.ensureIndex ({key:1}) Db.tbdefine.ensureIndex ({ke:1}) Db.cache.content.nodes.ensureIndex ({key:1 }) Db.b2c.goods.ensureIndex ({key:1})

Optimize Ecstore MongoDB Big Data reading and writing efficiency

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.