Speed, friends, is one of the important components of your project. While the resource is visited by 10-100 users per day, then everything is fine - the user is happy and invites his friends to you, friends of his friends and so on. The load is increasing ...
A person who looks at pictures, reads blogs, listens to music on the Internet, no matter what language your website is written in, which database is used and whether you use caching. It is important for him that access to interesting content be as fast as possible.
But over time, a successful project will always require
more performance due to an increase in project attendance.
Consider a bunch of
PHP + MySQL + Memcached .
')
To show the user an article with comments, you need:
- See if there is an article (with comments) in the cache.
- If not, then make an "expensive" JOIN text + comments
- Put everything in the cache
- Give content to user
The big minus in this algorithm is a muscular
JOIN (or any other DBMS).
The modern noSQL concept emerged as a response to normalized data structures.
Consider a bunch of
PHP + Memcached in the previous example:
- See if there is an article (with comments) in the cache.
- If not, then put it in the cache
- Give content to user
One point has become
"easier .
" No JOIN, but where to get the data? Store
in files .
The concept of “document” appears (for example: an article with comments). To specifically understand the
noSQL technology, I wanted,
as always, to “invent a bicycle.”
JIM2 PrototypeWanted:
Apache + mod_php + php_xcacheSpecify the path where the files will be stored:
define( 'STORAGE_PATH' , 'F:\\tmp\\jim2' );
Example of use:
a record$collection = new Collection();
$vasya = array
(
'name' => 'Vasya' ,
'sex' => 'male'
);
$masha = array
(
'name' => 'Masha' ,
'sex' => 'female'
);
$jim = array
(
'name' => 'Jim' ,
'sex' => 'male' ,
'type' => 'dog'
);
$collection->put($vasya);
$collection->put($masha);
$collection->put($jim);
$collection->createIndex( array ( 'name+sex' , 'sex' ) );
reading$collection = new Collection();
$keys = xcache_get( './index/sex/male' );
foreach ($keys as $key)
{
print_r( $collection-> get ($key) );
}
Features:
- Documents are stored as key / value.
- You can build indexes by document properties (additional keys are created)
- Each document has a _rev field indicating the document version. This will avoid collisions when locking a file for writing, as document versions are checked.
- Also the collection itself stores the version. Made in order to be able to convert the relevance of caches based on the collection of documents
What else is not, but will be:
- Fetching a collection using the API
- Pagination
- ... any of your suggestions
PS I didn’t compare read speeds, as it’s obvious that a direct access to the cache will always work quickly. But the insertion speed (100 items) pleased me: a bunch of MySQL + memcached fell behind (0.5417142) from JIM2 (0.4791223)