In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Memcached is a high-performance distributed memory cache server. The general purpose is to reduce the number of database accesses by caching database query results to improve the speed and scalability of dynamic Web applications. Obviously, it was necessary to understand its memory storage. Still that sentence, do not need to carry a bag, put their own finishing related memcached memory management framework to share.
I like to divide memory management into three learning units.
How to allocate memory?
How to reclaim memory?
How do I monitor memory?
Of course, the main exercise focus of this article also has.
How memory is allocated
How to recover memory
Recognize monitoring parameters
Verify some boundary data
1. How to allocate memory?
1.1 Default startup memory allocation
This output log can be read in two parts. The first part is the slab memory allocation information; the second part is the snooping enabled case.
There's three things I'm not sure about.
Why are there 2 "send buffer" every time you start... "And it's all 28, 32.
What is the meaning of the numbers 26-35 before each server listening? Why don't you start with zero.
udp in parenthesis, does it mean to listen to UDP type protocols? What about TCP monitoring?
There is a clearer guidance for this piece of trouble, but fortunately it is not clear that these points do not affect the overall situation.
1.2 Custom Startup Rules
Next, look at the output log by modifying the startup parameters. Compare and learn.
By comparison, we can easily understand some basic concepts. chunk size, growth factor.
There is one indicator worth mentioning.
## -t 4, monitor curr_connections## 4*2+2=10[root@hadoop1 hadoop]# echo stats| nc 127.0.0.1 11211| grep connectionSTAT curr_connections 10## -t 2, monitor curr_connections## 2*2+2=6[root@hadoop1 hadoop]# echo stats| nc 127.0.0.1 11211 |grep connectionSTAT curr_connections 6
3. Slab information before and after monitoring and saving data
Monitoring tabs before saving data information is as follows
[root@hadoop1 hadoop]# echo stats slabs | nc 127.0.0.1 11211STAT active_slabs 0STAT total_malloced 0
After saving the data, monitor the tabs information as follows
set key 1 1 11STOREDset key2 1 0 11STOREDset key2 1 0 11STOREDset key3 1 0 13STORED[root@hadoop1 hadoop]# echo stats slabs | nc 127.0.0.1 11211STAT 1:chunk_size 80STAT 1:chunks_per_page 13107STAT 1:total_pages 1STAT 1:total_chunks 13107STAT 1:used_chunks 2STAT 1:free_chunks 13105STAT 1:free_chunks_end 0STAT 1:mem_requested 108STAT 1:get_hits 0STAT 1:cmd_set 4STAT 1:delete_hits 0STAT 1:incr_hits 0STAT 1:decr_hits 0STAT 1:cas_hits 0STAT 1:cas_badval 0STAT 1:touch_hits 0STAT active_slabs 1STAT total_malloced 1048560END
By analyzing the logs, it is clear that the initiated operation records.
Four set or add operations were initiated. Two chunks of size 80 were used.
It is worth mentioning that the data saved is very small, but it takes up 160 bytes. What a waste of storage space.
By monitoring the total_mallocated metric, it is also verified that memcached adopts pre-allocation and grouping management mode.
Memory space is allocated only when there is real data to be saved. Also, stat tabs can only be monitored if the slab class is used.
2. How to recover memory
Memory collection is not convenient to verify, LRU algorithm use, we can verify from the side.
My idea for the drill: Add equal-sized data in batches. Then dump the data you want and confirm the smallest KEY.
Although simple and crude, but generally can explain the LRU algorithm bar.
2.1 Prepare to add data codes in bulk
Using spymcached as mentioned in memcached walkthrough (2) accessing memcached services
public void test111() throws ExecutionException, InterruptedException { final MemcachedClient mcc = MemcachedUtil.getSpyMemcachedClient(); final Lock lock = new ReentrantLock(); final String value="abcdef..... "; //Thread t1= new Thread(new Runnable() { @Override public void run() { for(int i=0;i
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.