MySQL Cluster with Memcache Support - mysql

I've been reading up about MySQL Cluster 7, and it appears that there is some support for a memcache storage engine.
Does the implemenation require any custom code in the application (making requests to memcache), or is it integrated to the point where I could
select cars.* from cars WHERE cars.id = 100
and MySQL cluster + memcache would be able to "automatically" look at the memcache cache first, and if there wasn't a hit, look in MySQL?
Like wise with update - Would i manually have to set the data in memcache with every modify or is there a mechanism that will do it for me?

Memcached would not provide the functionality that you describe. Memcached is key-value storage, and it does not automatically cache any query results. You would need to write code to store the results. Some frameworks make this easier.
MySQL's query caching can cache query results, but you're still hitting MySQL.
MySQL's NDB cluster is a clustered in-memory storage engine that is able to serve up relational data very fast thanks to load balancing and partitioning.

Take a look at this blog to learn more about the implementation and capabilities of the memcached API for MySQL Cluster:
http://www.clusterdb.com/mysql-cluster/scalabale-persistent-ha-nosql-memcache-storage-using-mysql-cluster/
Essentially the API is implemented as a plug-in to the memcached server which can then communicate directly with the data nodes, via memcached commands, without going through an SQL layer - giving you very fast native access to your data, with full persistence, scalability, write throughput and schema or schemaless data storage

Related

Why is MySQL more used than redis in persistence

I think two reasons
1 Mysql and redis both provide persistence, but why mysql is is used more than redis in persistence? Maybe redis has no index and cannot be used to answer queries directly from disk. But since we can query from memory, there is no need query from disk.
2 Redis saves data to disk on a periodic basis, then data loss may occur, but does Mysql save data to disk immediately after insert without time window?
Redis and MySQL are really two very different technologies. Redis primarily serves as a cache for storing data temporarily as a key-value store. While it is true that Redis can be configured to write back to a database or file under the hood, Redis itself is neither of these things. Instead, Redis is meant to store data which generally would be considered volatile.
On the other hand, MySQL is a database and a full blown data store. MySQL is suitable for permanently storing data, and also exposes a rich API for making it easy to query and search its data.
In terms of common ground, a query against a MySQL column which has a hash index would behave somewhat similarly to a lookup in a Redis cache, each using a certain key. But the difference is that, in general, Redis will perform about 100 times faster than a database. For this reason, when a lightning fast cache technology is needed, MySQL often will not be suitable for this purpose, but a cache like Redis might be suitable.

Storing in a JSON file vs. JSON object vs. MYSQL database

I've programmed a chat application using nodejs, expressjs and socket.io.
So, When I used MYSQL database the application slows down then I replaced it with storing the data using JSON objects (in the server-side of nodejs).
Now everything is ok and the application is working well, but If I want to release an update of the nodejs' app.js file it should be restarted, so, everything in the JSON objects will be deleted!
How can I fix this problem? and can I store in a JSON file to fix it? and will the application stay at the same speed or what?
Storing data in RAM will be always faster than writing to a database, but the problem in your case you need to persist it somewhere.
There are many solutions to this problem but if you are using JSON's, I recommend to look at mongodb database.
MongoDb supports multiple storage engines, but the one that you are interested is in memory.
An interesting architecture for you can be the following replica set configuration:
Primary with in-memory storage engine
Secondary with in-memory storage engine
An other Secondary with wiredtiger storage engine.
You will have the benefits of speed by storing in RAM, and also it will be persisted in the database.
A simpler possibility will be to use a key-store db like redis. Easier to configure.

Memcached on MySQL Server?

I just installed yum install memcached on MySQL Server. But then as service memcached status is Running.., what to do more as i do not think nothing is happening in performance. I think i still need to configure MySQL to work with Memcached.
What configuration need at MySQL end to talk with Memcached? (How to do?)
Or even still need to configuration from the Web Server end also?
Please help i'm stuck.
Memcached is not a MySQL performance plugin - it's commonly used as a write-though or write-back caching system - often where you need to store commonly used key/value pairs without hitting your database unless they change - thus reducing load on your DB.
Visiting the Memcached website provides useful information:
Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Ultra-simplistic pseudo-code example:
Read:
if data in memcache {
// Retrieve and use
} else {
// Pull from DB, use and write to memcache
}
Or, here, Memcached describes a simple example for caching results:
Cache Results:
function get_foo(foo_id)
foo = memcached_get("foo:" . foo_id)
return foo if defined foo
foo = fetch_foo_from_database(foo_id)
memcached_set("foo:" . foo_id, foo)
return foo
end
It doesn't do anything unless you write your software/codebase to use it (usually, you write your DB functions to check the cache before hitting your DB). It's worth reading the Memcached Story of caching to understand a basic use-case scenario.
Historically, some have compared it to using HEAP or memory tables in MySQL, but it's not the same and can be distributed on many machines in a cluster and/or over a network where you have free/unallocated memory available for use - even on one server.
If you want to understand it's value at scale, then look no-further than the list of companies that use it.
Are you searching for this?
Mysql5.6 now support memcache integrated version plugin.
If in that case, you don't need to install another memcached server.
Simply install mysql 5.6. and memcached plugin.
Then.. as you can see in that page....
you can send memacached command to memcached server and memcached plugin automatically write to backup table which you want.
One thing that I think there should be more improvement is table field type.
Only varchar/text/blob type can be possible( backup table field which you want to interact with memcached server... ).
PS)
I heard that memcached plugin DML throughput is amazing.
but when I tried, I've only? got 30% improvement...

Rails 3: How to implement a query cache in MongoDB

I did some research about MongoDB and recognised that it doesn't have any query cache.
MongoDB does not implement a query cache: MongoDB serves all queries directly from the indexes and/or data files. (http://docs.mongodb.org/manual/faq/fundamentals/)
Is there a way to implement a query cache in Rails for MongoDB? I just want the same behaviour as the MySQL query cache. The same database query should be more faster on the second time.
Thanks!
You could add a caching layer using memcached, but MongoDB will probably still have the data paged into memory from the last read/write operation already. Using your MongoDB server memory for memcached will compete with it's memory mapped file model. Less memory for MongoDB means more swapping to disk.
If you're running map reduce jobs (large enough to cause paging), it may be worth caching results, but tracking updates properly could be very tricky.

MySQL Cluster is a NoSQL technology?

MySQL Cluster is a NoSQL technology? Or is another way to use the relational database?
MySQL Cluster uses MySQL Servers as API nodes to provide SQL access/a relational view to the data. The data itself is stored in the data nodes - which are separate processes. The fastest way to access the data is through the C++ API (NDB API) - in fact that is how the MySQL Server gets to the data.
There are a number of NoSQL access methods for getting to the data (that avoid going through the MySQL Server/releational view) including Rest, Java, JPA, LDAP and most recently the Memcached key-value store API.
It is another way to use the database by spreading it across multiple machines and allowing a simplified concurrent-master setup. It comes with a bit of a cost in that your indexes cannot exceed the amount of RAM available to hold them. To you application, it looks no different than regular MySQL.
Perhaps take a look at Can MySQL Cluster handle a terabyte database.