In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the introduction and practice of distributed cache system memcached, which is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
What is memcached?
Memcached is a high-performance, distributed in-memory object caching system developed by Danga Interactive, which is used to reduce database load and improve access speed in dynamic applications.
What can memcached cache?
By maintaining a unified huge hash table in memory, Memcached can be used to store data in various formats, including images, videos, files and database retrieval results.
Is memcached fast?
Very fast. Memcached uses libevent (epoll, if possible, under linux) to balance any number of open links, uses the non-blocking network Imaco, implements reference counting for internal objects (so objects can be in multiple states for multiple clients), and uses its own page block allocator and hash table Therefore, virtual memory will not be fragmented and the time complexity of virtual memory allocation can be guaranteed to be O (1).
Danga Interactive has developed memcached to speed up Danga Interactive. Currently, LiveJournal.com is providing 1 million users with as many as 20 million page visits a day. These are done by a cluster of web servers and database servers. Memcached has almost completely abandoned the way that any data is read from the database. At the same time, it also reduces the speed at which users view pages, better resource allocation, and access to the database when memcache fails.
Characteristics of memcached
Memcached cache is distributed and can be accessed by multiple users on different hosts at the same time, so it solves the limitation that shared memory can only be used on a stand-alone computer, let alone disk overhead and blocking when using a database to do similar things.
The use of memcached
Memcached server-side installation (installed here as a system service)
Download file: memcached 1.2.1 for Win32 binaries (Dec 23, 2006)
1. Extract the file to
C:\ memcached
two。 Command line input
'c:\ memcached\ memcached.exe-d install'
3. Command line input
'c:\ memcached\ memcached.exe-d start'
This command starts memcached, and the default listening port is 11211, and its help can be viewed through memcached.exe-h.
.NET memcached client library
Download file: https://sourceforge.net/projects/memcacheddotnet/
There are two versions of. Net1.1 and. Net 2.0 and a good example.
Application
1. Put Commons.dll,ICSharpCode.SharpZipLib.dll,log4net.dll,Memcached.ClientLibrary.dll and so on into the bin directory
two。 Quote Memcached.ClientLibrary.dll
3. Code
Namespace Memcached.MemcachedBench {using System; using System.Collections; using Memcached.ClientLibrary; public class MemcachedBench {[STAThread] public static void Main (String [] args) {string [] serverlist = {"10.0.0.131R 11211", "10.0.0.132R 11211"} / / initialization pool SockIOPool pool = SockIOPool.GetInstance (); pool.SetServers (serverlist); pool.InitConnections = 3; pool.MinConnections = 3; pool.MaxConnections = 5; pool.SocketConnectTimeout = 1000; pool.SocketTimeout = 3000; pool.MaintenanceSleep = 30 Pool.Failover = true; pool.Nagle = false; pool.Initialize (); / / get the client instance MemcachedClient mc = new MemcachedClient (); mc.EnableCompression = false; Console.WriteLine ("- test -") Mc.Set ("test", "my value"); / / stores the data to the cache server, where the string "my value" is cached, and key is "test" if (mc.KeyExists ("test")) / / Test cache exists item {Console.WriteLine ("test is Exists") with key of test Console.WriteLine (mc.Get ("test"). ToString ()); / / get the project with test key in the cache} else {Console.WriteLine ("test not Exists");} Console.ReadLine (); mc.Delete ("test") / / remove the item if (mc.KeyExists ("test")) {Console.WriteLine ("test is Exists"); Console.WriteLine (mc.Get ("test"). ToString ()) whose key is test in the cache;} else {Console.WriteLine ("test not Exists") } Console.ReadLine (); SockIOPool.GetInstance () .Shutdown (); / / close the pool, close sockets}
4. Running result
On the distributed cache system memcached introduction and practice is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.