CN115563174A - Method and system for managing user hot spot data in memory - Google Patents
Method and system for managing user hot spot data in memory Download PDFInfo
- Publication number
- CN115563174A CN115563174A CN202211294605.7A CN202211294605A CN115563174A CN 115563174 A CN115563174 A CN 115563174A CN 202211294605 A CN202211294605 A CN 202211294605A CN 115563174 A CN115563174 A CN 115563174A
- Authority
- CN
- China
- Prior art keywords
- user
- linked list
- data
- generation
- pointer
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2457—Query processing with adaptation to user needs
- G06F16/24578—Query processing with adaptation to user needs using ranking
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
- G06F16/215—Improving data quality; Data cleansing, e.g. de-duplication, removing invalid entries or correcting typographical errors
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2272—Management thereof
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computational Linguistics (AREA)
- Software Systems (AREA)
- Quality & Reliability (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明提供了一种内存中用户热点数据管理的方法,该方法为:1、定义用户链表结构;2、用户登录时,从内存的用户字典中查找用户,如果不存在,则从数据库中查找用户,接着把此用户加入1代用户链表的头部;3、用户进入游戏时,从内存的用户字典中查找用户,把用户加入2代用户链表的头部,并从1代用户链表里删除,4、用户进入活动后,从内存的用户字典中查找用户,把用户加入3代用户链表的头部,并从2代用户链表里删除,5、需要读取用户数据时,从内存的用户字典中查找用户指针,通过指针读取到用户链表中用户数据,如果不存在则从数据库读取后插入到1代用户链表的头部,并存储指针到用户字典中;保证活跃用户更可能被保存下来。
The present invention provides a method for managing user hotspot data in the internal memory. The method is as follows: 1. Define the structure of the user linked list; 2. When the user logs in, search for the user from the user dictionary in the internal memory, and if it does not exist, search for the user from the database User, then add this user to the head of the first-generation user linked list; 3. When the user enters the game, look up the user from the user dictionary in the memory, add the user to the head of the second-generation user linked list, and delete it from the first-generation user linked list , 4. After the user enters the activity, look up the user from the user dictionary in the memory, add the user to the head of the 3rd generation user linked list, and delete it from the 2nd generation user linked list. Look up the user pointer in the dictionary, read the user data in the user linked list through the pointer, if it does not exist, read it from the database and insert it into the head of the first-generation user linked list, and store the pointer in the user dictionary; to ensure that active users are more likely to be Save it.
Description
技术领域technical field
本发明涉及数据存储技术领域,特别是一种内存中用户热点数据管理的方法及其系统。The invention relates to the technical field of data storage, in particular to a method and system for managing user hotspot data in memory.
背景技术Background technique
所谓“静态热点数据”,就是能够提前预测的热点数据。例如,可以通过卖家报名的方式提前筛选出来,通过报名系统对这些热点商品进行打标。另外,还可以通过大数据分析来提前发现热点商品,比如分析历史成交记录、用户的购物车记录,来发现哪些商品可能更热门、更好卖,这些都是可以提前分析出来的热点。The so-called "static hotspot data" refers to hotspot data that can be predicted in advance. For example, it can be screened out in advance through the registration of sellers, and these hot products can be marked through the registration system. In addition, big data analysis can also be used to discover hot products in advance, such as analyzing historical transaction records and user shopping cart records to find out which products may be more popular and sell better. These are hot spots that can be analyzed in advance.
所谓“动态热点数据”,就是不能被提前预测到的,系统在运行过程中临时产生的热点。例如,卖家在抖音上做了广告,然后商品一下就火了,导致它在短时间内被大量购买。The so-called "dynamic hotspot data" refers to hotspots that cannot be predicted in advance and are temporarily generated during the operation of the system. For example, a seller advertised on Douyin, and then the product became popular immediately, causing it to be bought in large quantities in a short period of time.
在游戏服务器中,用户信息不仅会存储在数据库和分布式缓存中,在程序内存也会维护一份用户数据,因为程序内存没有网络损耗,是最快的读取方式。但由于内存的稀缺性,一台服务器的内存容量是有限,不可能在内存中缓存全量的用户数据,那么在有限的内存下如何尽可能的维护热点用户数据呢,这是本专利要解决的问题。In the game server, user information is not only stored in the database and distributed cache, but also maintains a copy of user data in the program memory, because the program memory has no network loss and is the fastest way to read it. However, due to the scarcity of memory, the memory capacity of a server is limited, and it is impossible to cache a full amount of user data in the memory, so how to maintain hot user data as much as possible under the limited memory, this is what this patent wants to solve question.
发明内容Contents of the invention
为克服上述问题,本发明的目的是提供。不增加内存容量的同时,保证活跃用户数据更可能被保存下来。In order to overcome the above-mentioned problems, the object of the present invention is to provide. While not increasing memory capacity, it is more likely that active user data will be preserved.
本发明采用以下方案实现:一种内存中用户热点数据管理的方法,所述方法包括如下步骤:The present invention adopts the following solutions to realize: a method for managing user hotspot data in memory, said method comprising the following steps:
步骤S1、定义用户链表结构,把用户链表分为3段,分别是1代用户链表,2代用户链表,3代用户链表,3段链表从右往左依次相连,并且用字典存储用户编号和用户链表数据指针;Step S1, define the structure of the user linked list, divide the user linked list into 3 segments, namely the 1st generation user linked list, the 2nd generation user linked list, the 3rd generation user linked list, the 3 segment linked lists are connected sequentially from right to left, and use a dictionary to store user numbers and User linked list data pointer;
步骤S2、用户登录时,从内存的用户字典中查找用户,如果存在,则返回用户数据,并进入步骤S3;如果不存在,则从数据库中查找用户,接着把此用户加入1代用户链表的头部,并记录为1代用户链表链头的节点指针;Step S2, when the user logs in, look up the user from the user dictionary in the internal memory, if it exists, return the user data, and go to step S3; if it does not exist, look up the user from the database, and then add this user to the first-generation user linked list Head, and recorded as the node pointer of the head of the 1st generation user linked list;
步骤S3、用户进入游戏时,从内存的用户字典中查找用户,把用户加入2代用户链表的头部,并从1代用户链表里删除,记录为2代用户链表链头的节点指针;Step S3, when the user enters the game, look up the user from the user dictionary in the memory, add the user to the head of the 2nd generation user linked list, delete it from the 1st generation user linked list, and record it as a node pointer at the head of the 2nd generation user linked list;
步骤S4、用户进入活动后,从内存的用户字典中查找用户,把用户加入3代用户链表的头部,并从2代用户链表里删除,记录为3代用户链表链头的节点指针;Step S4, after the user enters the activity, look up the user from the user dictionary in the memory, add the user to the head of the 3rd generation user linked list, delete it from the 2nd generation user linked list, and record it as the node pointer of the 3rd generation user linked list link head;
步骤S5、需要读取用户数据时,从内存的用户字典中查找用户指针,通过指针读取到用户链表中用户数据,如果存在则返回用户数据,如果不存在则从数据库读取后插入到1代用户链表的头部,并存储指针到用户字典中。Step S5, when user data needs to be read, look up the user pointer from the user dictionary in the internal memory, read the user data in the user linked list through the pointer, return the user data if it exists, and insert it into 1 after reading it from the database if it does not exist Replace the head of the user linked list and store the pointer to the user dictionary.
进一步的,所述用户链表结构如下{uid,pre,next,userinfo,group},其中,uid:用户编号;pre:上一个用户数据的指针;next:下一个用户数据的指针;userinfo:具体的用户信息;group:数据分代类型,group值为1、2、3,表示代数;所有的用户数据通过pre和next上下指针相连,形成一个用户链表,用户链表跟内存缓存一样,存储着用户数据。Further, the structure of the user linked list is as follows {uid, pre, next, userinfo, group}, wherein, uid: user number; pre: pointer to the previous user data; next: pointer to the next user data; userinfo: specific User information; group: data generation type, the group value is 1, 2, 3, indicating algebra; all user data are connected through pre and next pointers to form a user linked list, which stores user data just like the memory cache .
进一步的,所述用户字典存储用户编号和用户链表数据指针,定义为:map[int]*user,int类型的关键字key是用户编号,值*user类型是用户指针,指向具体的用户链表数据,这样通过用户uid能最快速的得到数据在链表中的位置。Further, the user dictionary stores the user number and the user linked list data pointer, which is defined as: map[int]*user, the keyword key of the int type is the user number, and the value *user type is the user pointer, pointing to the specific user linked list data , so that the position of the data in the linked list can be obtained most quickly through the user uid.
进一步的,用户链表存储数据时,如果用户链表总长度大于预设长度值,则从用户链表的链尾开始,从1代用户链表开始向3代用户链表移动,移除设定数量的用户数据。Further, when the user linked list stores data, if the total length of the user linked list is greater than the preset length value, start from the end of the user linked list, move from the 1st generation user linked list to the 3rd generation user linked list, and remove the set amount of user data .
进一步的,所述步骤S5进一步具体为:读取用户数据时,优先从用户字典map中查找数据,如果存在则返回用户数据,如果不存在则从数据库读取用户数据后插入到1代用户链表的头部,并存储指针到用户字典map中,其中预设长度值是10000,即默认只存储10000个活跃用户在内存中的数据,如果用户链表总长度大于10000,则从链表尾部开始,通过用户链表结构的pre逐一向左进行前进,移除尾部开始的最后100个用户元素,这样代数越高、位置越靠左的用户更容易被保存在内存数据中。Further, the step S5 is further specifically: when reading the user data, look up the data first from the user dictionary map, if it exists, return the user data, if it does not exist, read the user data from the database and insert it into the first-generation user linked list head, and store pointers to the user dictionary map, where the preset length value is 10000, that is, by default, only the data of 10000 active users in memory is stored. If the total length of the user linked list is greater than 10000, start from the end of the linked list and pass The pre of the user linked list structure advances to the left one by one, and removes the last 100 user elements from the end, so that users with higher algebra and positions further to the left are more likely to be stored in memory data.
本发明提供了一种内存中用户热点数据管理的系统,所述系统包括:链表定义模块、活跃一用户信息存储模块、活跃二用户信息存储模块、活跃三用户信息存储模块、数据读取模块;The present invention provides a system for managing user hotspot data in memory. The system includes: a linked list definition module, an active user information storage module, an active user information storage module, an active user information storage module, and a data reading module;
所述链表定义模块,定义用户链表结构,把用户链表分为3段,分别是1代用户链表,2代用户链表,3代用户链表,3段链表从右往左依次相连,并且用字典存储用户编号和用户链表数据指针;The linked list definition module defines the structure of the user linked list, and divides the user linked list into 3 sections, which are respectively the 1st generation user linked list, the 2nd generation user linked list, the 3rd generation user linked list, and the 3 section linked lists are connected successively from right to left, and are stored in a dictionary User number and user linked list data pointer;
所述活跃一用户信息存储模块,在用户登录时,从内存的用户字典中查找用户,如果存在,则返回用户数据,并进入活跃二用户信息存储模块;如果不存在,则从数据库中查找用户,接着把此用户加入1代用户链表的头部,并记录为1代用户链表链头的节点指针;The active user information storage module, when the user logs in, searches the user from the user dictionary in the memory, if it exists, returns the user data, and enters the active second user information storage module; if it does not exist, it searches the user from the database , and then add this user to the head of the first-generation user linked list, and record it as the node pointer of the first-generation user linked list link head;
所述活跃二用户信息存储模块,在用户进入游戏时,从内存的用户字典中查找用户,把用户加入2代用户链表的头部,并从1代用户链表里删除,记录为2代用户链表链头的节点指针;The active second user information storage module, when the user enters the game, searches the user from the user dictionary in the internal memory, adds the user to the head of the 2nd generation user linked list, and deletes it from the 1st generation user linked list, and records it as the 2nd generation user linked list The node pointer of the chain head;
所述活跃三用户信息存储模块,在用户进入活动后,从内存的用户字典中查找用户,把用户加入3代用户链表的头部,并从2代用户链表里删除,记录为3代用户链表链头的节点指针;The active three user information storage module, after the user enters the activity, searches the user from the user dictionary in the memory, adds the user to the head of the 3rd generation user linked list, and deletes it from the 2nd generation user linked list, and records it as the 3rd generation user linked list The node pointer of the chain head;
所述数据读取模块,需要读取用户数据时,从内存的用户字典中查找用户指针,通过指针读取到用户链表中用户数据,如果存在则返回用户数据,如果不存在则从数据库读取后插入到1代用户链表的头部,并存储指针到用户字典中。The data reading module, when user data needs to be read, looks up the user pointer from the user dictionary in the internal memory, reads the user data in the user linked list through the pointer, returns the user data if it exists, and reads it from the database if it does not exist Then insert it into the head of the first-generation user linked list, and store the pointer in the user dictionary.
进一步的,所述用户链表结构如下{uid,pre,next,userinfo,group},其中,uid:用户编号;pre:上一个用户数据的指针;next:下一个用户数据的指针;userinfo:具体的用户信息;group:数据分代类型,group值为1、2、3,表示代数;所有的用户数据通过pre和next上下指针相连,形成一个用户链表,用户链表跟内存缓存一样,存储着用户数据。Further, the structure of the user linked list is as follows {uid, pre, next, userinfo, group}, wherein, uid: user number; pre: pointer to the previous user data; next: pointer to the next user data; userinfo: specific User information; group: data generation type, the group value is 1, 2, 3, indicating algebra; all user data are connected through pre and next pointers to form a user linked list, which stores user data just like the memory cache .
进一步的,所述用户字典存储用户编号和用户链表数据指针,定义为:map[int]*user,int类型的关键字key是用户编号,值*user类型是用户指针,指向具体的用户链表数据,这样通过用户uid能最快速的得到数据在链表中的位置。Further, the user dictionary stores the user number and the user linked list data pointer, which is defined as: map[int]*user, the keyword key of the int type is the user number, and the value *user type is the user pointer, pointing to the specific user linked list data , so that the position of the data in the linked list can be obtained most quickly through the user uid.
进一步的,用户链表存储数据时,如果用户链表总长度大于预设长度值,则从用户链表的链尾开始,从1代用户链表开始向3代用户链表移动,移除设定数量的用户数据。Further, when the user linked list stores data, if the total length of the user linked list is greater than the preset length value, start from the end of the user linked list, move from the 1st generation user linked list to the 3rd generation user linked list, and remove the set amount of user data .
进一步的,所述数据读取模块的实现方式进一步具体为:读取用户数据时,优先从用户字典map中查找数据,如果存在则返回用户数据,如果不存在则从数据库读取用户数据后插入到1代用户链表的头部,并存储指针到用户字典map中,其中预设长度值是10000,即默认只存储10000个活跃用户在内存中的数据,如果用户链表总长度大于10000,则从链表尾部开始,通过用户链表结构的pre逐一向左进行前进,移除尾部开始的最后100个用户元素,这样代数越高、位置越靠左的用户更容易被保存在内存数据中。Further, the implementation of the data reading module is further specifically: when reading user data, first look up data from the user dictionary map, if it exists, return the user data, if it does not exist, read the user data from the database and insert Go to the head of the first-generation user linked list, and store the pointer in the user dictionary map, where the preset length value is 10000, that is, only store the data of 10000 active users in memory by default. If the total length of the user linked list is greater than 10000, then from Starting from the end of the linked list, move forward one by one to the left through the pre of the user linked list structure, and remove the last 100 user elements starting from the end, so that users with higher algebra and positions further to the left are easier to be stored in memory data.
本发明的有益效果在于:使用用户分代的思想,把用户通过不同的业务行为进行分代,并通过前后指针相连,使其形成一个分代的链表,链表从左往右形成一个活跃度的递减趋势,如果内存不足,要移除内存中的用户数据,则从最右边的链尾起开始移除。这样可以保证活跃用户更可能被保存下来。The beneficial effects of the present invention are: using the idea of user generation, users are divided into generations through different business behaviors, and connected by front and back pointers to form a generational linked list, and the linked list forms an activity level from left to right. Decreasing trend, if the memory is insufficient, to remove the user data in the memory, start to remove from the end of the rightmost chain. This ensures that active users are more likely to be saved.
附图说明Description of drawings
图1是本发明的方法流程示意图。Fig. 1 is a schematic flow chart of the method of the present invention.
图2是本发明的系统工作原理图。Fig. 2 is a working principle diagram of the system of the present invention.
具体实施方式detailed description
下面结合附图对本发明做进一步说明。The present invention will be further described below in conjunction with the accompanying drawings.
请参阅图1所示,本发明的一种内存中用户热点数据管理的方法,所述方法包括如下步骤:Please refer to shown in Fig. 1, a kind of method of user hotspot data management in memory of the present invention, described method comprises the following steps:
步骤S1、定义用户链表结构,把用户链表分为3段,分别是1代用户链表,2代用户链表,3代用户链表,3段链表从右往左依次相连,并且用字典存储用户编号和用户链表数据指针;Step S1, define the structure of the user linked list, divide the user linked list into 3 segments, namely the 1st generation user linked list, the 2nd generation user linked list, the 3rd generation user linked list, the 3 segment linked lists are connected sequentially from right to left, and use a dictionary to store user numbers and User linked list data pointer;
步骤S2、用户登录时,从内存的用户字典中查找用户,如果存在,则返回用户数据,并进入步骤S3;如果不存在,则从数据库中查找用户,接着把此用户加入1代用户链表的头部,并记录为1代用户链表链头的节点指针;Step S2, when the user logs in, look up the user from the user dictionary in the internal memory, if it exists, return the user data, and go to step S3; if it does not exist, look up the user from the database, and then add this user to the first-generation user linked list Head, and recorded as the node pointer of the head of the 1st generation user linked list;
步骤S3、用户进入游戏时,从内存的用户字典中查找用户,把用户加入2代用户链表的头部,并从1代用户链表里删除,记录为2代用户链表链头的节点指针;Step S3, when the user enters the game, look up the user from the user dictionary in the memory, add the user to the head of the 2nd generation user linked list, delete it from the 1st generation user linked list, and record it as a node pointer at the head of the 2nd generation user linked list;
步骤S4、用户进入活动后,从内存的用户字典中查找用户,把用户加入3代用户链表的头部,并从2代用户链表里删除,记录为3代用户链表链头的节点指针;Step S4, after the user enters the activity, look up the user from the user dictionary in the memory, add the user to the head of the 3rd generation user linked list, delete it from the 2nd generation user linked list, and record it as the node pointer of the 3rd generation user linked list link head;
步骤S5、需要读取用户数据时,从内存的用户字典中查找用户指针,通过指针读取到用户链表中用户数据,如果存在则返回用户数据,如果不存在则从数据库读取后插入到1代用户链表的头部,并存储指针到用户字典中。Step S5, when user data needs to be read, look up the user pointer from the user dictionary in the internal memory, read the user data in the user linked list through the pointer, return the user data if it exists, and insert it into 1 after reading it from the database if it does not exist Replace the head of the user linked list and store the pointer to the user dictionary.
下面结合一具体实施例对本发明做进一步说明:The present invention will be further described below in conjunction with a specific embodiment:
一种内存中用户热点数据管理的方法:A method for managing user hotspot data in memory:
步骤一、定义用户链表结构{uid,pre,next,userinfo,group},把链表分为3段,分别是1代用户链表,2代用户链表,3代用户链表,3段链表从右往左依次相连,并且用字典存储用户编号和用户链表数据指针。Step 1. Define the structure of the user linked list {uid, pre, next, userinfo, group}, and divide the linked list into 3 segments, namely the 1st generation user linked list, the 2nd generation user linked list, the 3rd generation user linked list, and the 3 segmented linked list from right to left They are connected in turn, and use a dictionary to store user numbers and user linked list data pointers.
首先定义内存中用户数据是以一种链表的结构存储,user结构如下{uid,pre,next,userinfo,group},uid:用户编号;pre:上一个用户数据的指针;next:下一个用户数据的指针;userinfo:具体的用户信息;group:数据分代类型,值为1、2、3,表示代数。所有的用户数据通过pre和next上下指针相连,形成一个用户链表。链表作为内存缓存一样,存储着用户数据,但为了最快的得到用户数据,所述用户字典存储用户编号和用户链表数据指针,用户字典来存储用户指针map[int]*user,int类型的key是用户编号,值*user类型是用户指针,指向具体的用户链表数据,这样可用通过用户id最快速的得到数据在链表中的位置。Firstly, it is defined that the user data in the memory is stored in a linked list structure. The user structure is as follows {uid, pre, next, userinfo, group}, uid: user number; pre: pointer to the previous user data; next: next user data pointer; userinfo: specific user information; group: data generation type, the value is 1, 2, 3, indicating algebra. All user data are connected through pre and next up and down pointers to form a user linked list. As a memory cache, the linked list stores user data, but in order to obtain user data as quickly as possible, the user dictionary stores user numbers and user linked list data pointers, and the user dictionary stores user pointers map[int]*user, key of type int It is the user number, and the value *user type is the user pointer, which points to the specific user linked list data, so that the position of the data in the linked list can be obtained most quickly through the user id.
步骤二、用户登录时,从内存的用户字典中查找用户,如果不存在则从数据库中查找用户,接着把此用户加入1代用户链表的头部,并记录为1代用户链头的节点指针。Step 2. When the user logs in, look up the user from the user dictionary in the internal memory. If it does not exist, look up the user from the database, and then add this user to the head of the first-generation user list, and record it as the node pointer of the first-generation user chain head .
当用户登陆时,先从map中查找id是否存在,如果存在直接返回用户数据。如果不存在则从数据库读取用户信息userinfo记为usern,假设当前1代用户链头指针是指向user1a,user1a的pre指向user2a,user1a的next指向user1b,链表形态如下:xxx-user2b-user2a-user1a-user1b-xxx,其中前后xxx是表示省略号的意思,即前面和后面还有其他数据;现在需要把usern变为1代用户链表的链头,则把user2a.next指向usern,usern的pre指向user2a,usern.next指向user1a,user1a.pre指向usern。最后形成新的链表:xxx-user2b-user2a-usern-user1a-user1b-xxx,并记录最新的1代用户链头指针为usern。When the user logs in, first check whether the id exists in the map, and return the user data directly if it exists. If it does not exist, read the user information userinfo from the database and record it as usern. Assume that the current 1st generation user chain head pointer points to user1a, the pre of user1a points to user2a, and the next of user1a points to user1b. The form of the linked list is as follows: xxx-user2b-user2a-user1a -user1b-xxx, where xxx before and after means ellipsis, that is, there are other data in the front and back; now usern needs to be changed to the chain head of the 1st generation user list, then user2a.next points to usern, usern's pre points to user2a , usern.next points to user1a, and user1a.pre points to usern. Finally, a new linked list is formed: xxx-user2b-user2a-usern-user1a-user1b-xxx, and the latest 1st generation user link head pointer is recorded as usern.
步骤三、用户进入游戏时,从内存的用户字典中查找用户,把用户加入2代用户链表的头部,并从1代用户链表里删除,记录为2代用户链头的节点指针。Step 3. When the user enters the game, look up the user from the user dictionary in the memory, add the user to the head of the 2nd generation user linked list, delete it from the 1st generation user linked list, and record it as the node pointer of the 2nd generation user link head.
当用户进入游戏时,此时视此用户为二级活跃用户,从内存字典map中查找key为id的用户,得到*user指向usern,把usern.next指向的节点user1a记录为1代用户链头指针节点,再把usern移动到当前用户2代链头user2b之前,形成如下链表:xxx-usern-user2b-user2a-user1a-user1b-xxx。把usern移动到2代用户链表的头部后把usern记录为新的2代用户链头指针节点。When a user enters the game, the user is regarded as a second-level active user at this time, and the user whose key is id is searched from the memory dictionary map, and *user points to usern, and the node user1a pointed to by usern.next is recorded as the first-generation user chain head Pointer node, and then move usern to the front of the current user 2 generation chain head user2b to form the following linked list: xxx-usern-user2b-user2a-user1a-user1b-xxx. After usern is moved to the head of the 2nd generation user chain list, usern is recorded as a new 2nd generation user chain head pointer node.
步骤四、用户进入活动后,从内存的用户字典中查找用户,把用户加入3代用户链表的头部,并从2代用户链表里删除,记录为3代用户链头的节点指针。Step 4. After the user enters the activity, look up the user from the user dictionary in the memory, add the user to the head of the 3rd generation user linked list, delete it from the 2nd generation user linked list, and record it as the node pointer of the 3rd generation user link head.
当用户进入活动时,此时视此用户为三级活跃用户,从内存字典map中查找key为id的用户,得到*user指向usern,把usern.next指向的节点user2b记录为2代用户链头指针节点,再把usern移动到当前用户3代链头之前,形成如下链表:usern-xxx-user2b-user2a-user1a-user1b-xxx。把usern移动到3代用户链表的头部后把usern记录为新的3代用户链头指针节点When a user enters an activity, the user is regarded as a third-level active user at this time, and the user whose key is id is searched from the memory dictionary map, and *user points to usern, and the node user2b pointed to by usern.next is recorded as the second-generation user chain head Pointer node, and then move usern to the front of the 3rd generation chain head of the current user to form the following linked list: usern-xxx-user2b-user2a-user1a-user1b-xxx. After moving usern to the head of the 3rd generation user list, record usern as the new 3rd generation user chain head pointer node
步骤五、系统需要读取用户数据时,从内存的用户字典中查找用户指针,通过指针读取到用户链表中用户数据,如果不存在则从数据库读取后插入到1代用户链表的头部,并存储指针到map中,其中预设长度值是10000,如果链表总长度大于10000,则从用户链表的链尾开始,从1代用户开始向3代用户移动,移除100个用户数据。Step 5. When the system needs to read user data, look up the user pointer from the user dictionary in the memory, and read the user data in the user linked list through the pointer. If it does not exist, read it from the database and insert it into the head of the first-generation user linked list , and store pointers in the map, where the preset length value is 10000. If the total length of the linked list is greater than 10000, start from the end of the user linked list, move from the first generation of users to the third generation of users, and remove 100 user data.
系统需要读取用户数据时,优先从用户字典map中查找数据,如果存在则返回用户数据,如果不存在则从数据库读取用户数据后插入到1代用户链表的头部,并存储指针到map中,系统默认只存储10000个活跃用户在内存中的数据,如果链表总长度大于10000,则从链表尾部开始,通过pre逐一向左进行前进,移除尾部开始的最后100个用户元素,那么达到的效果就是代数越高、位置越靠左的用户更容易被保存在内存数据中。When the system needs to read user data, it first looks up the data from the user dictionary map. If it exists, it returns the user data. If it does not exist, it reads the user data from the database and inserts it into the head of the first-generation user linked list, and stores the pointer to the map. , the system defaults to only storing the data of 10,000 active users in the memory. If the total length of the linked list is greater than 10,000, start from the end of the linked list, advance to the left one by one through pre, and remove the last 100 user elements from the end, then reach The effect of is that users with higher algebra and positions further to the left are more likely to be stored in memory data.
请参阅图2所示,本发明提供了一种内存中用户热点数据管理的系统,所述系统包括:链表定义模块、活跃一用户信息存储模块、活跃二用户信息存储模块、活跃三用户信息存储模块、数据读取模块;Please refer to Fig. 2, the present invention provides a system for managing user hotspot data in memory, the system includes: a linked list definition module, an active user information storage module, an active second user information storage module, and an active three user information storage module module, data reading module;
所述链表定义模块,定义用户链表结构,把用户链表分为3段,分别是1代用户链表,2代用户链表,3代用户链表,3段链表从右往左依次相连,并且用字典存储用户编号和用户链表数据指针;所述用户链表结构如下{uid,pre,next,userinfo,group},其中,uid:用户编号;pre:上一个用户数据的指针;next:下一个用户数据的指针;userinfo:具体的用户信息;group:数据分代类型,group值为1、2、3,表示代数;所有的用户数据通过pre和next上下指针相连,形成一个用户链表,用户链表跟内存缓存一样,存储着用户数据。The linked list definition module defines the structure of the user linked list, and divides the user linked list into 3 sections, which are respectively the 1st generation user linked list, the 2nd generation user linked list, the 3rd generation user linked list, and the 3 section linked lists are connected successively from right to left, and are stored in a dictionary User number and user linked list data pointer; the user linked list structure is as follows {uid, pre, next, userinfo, group}, wherein, uid: user number; pre: the pointer of the previous user data; next: the pointer of the next user data ; userinfo: specific user information; group: data generation type, the group value is 1, 2, 3, indicating algebra; all user data are connected through pre and next pointers to form a user linked list, and the user linked list is the same as the memory cache , which stores user data.
所述活跃一用户信息存储模块,在用户登录时,从内存的用户字典中查找用户,如果存在,则返回用户数据,并进入活跃二用户信息存储模块;如果不存在,则从数据库中查找用户,接着把此用户加入1代用户链表的头部,并记录为1代用户链表链头的节点指针;The active user information storage module, when the user logs in, searches the user from the user dictionary in the memory, if it exists, returns the user data, and enters the active second user information storage module; if it does not exist, it searches the user from the database , and then add this user to the head of the first-generation user linked list, and record it as the node pointer of the first-generation user linked list link head;
所述用户字典存储用户编号和用户链表数据指针,定义为:map[int]*user,int类型的关键字key是用户编号,值*user类型是用户指针,指向具体的用户链表数据,这样通过用户uid能最快速的得到数据在链表中的位置。Described user dictionary stores user number and user linked list data pointer, is defined as: map[int]*user, the keyword key of int type is the user number, and value*user type is the user pointer, points to concrete user linked list data, like this through The user uid can get the position of the data in the linked list most quickly.
所述活跃二用户信息存储模块,在用户进入游戏时,从内存的用户字典中查找用户,把用户加入2代用户链表的头部,并从1代用户链表里删除,记录为2代用户链表链头的节点指针;The active second user information storage module, when the user enters the game, searches the user from the user dictionary in the internal memory, adds the user to the head of the 2nd generation user linked list, and deletes it from the 1st generation user linked list, and records it as the 2nd generation user linked list The node pointer of the chain head;
所述活跃三用户信息存储模块,在用户进入活动后,从内存的用户字典中查找用户,把用户加入3代用户链表的头部,并从2代用户链表里删除,记录为3代用户链表链头的节点指针;The active three user information storage module, after the user enters the activity, searches the user from the user dictionary in the memory, adds the user to the head of the 3rd generation user linked list, and deletes it from the 2nd generation user linked list, and records it as the 3rd generation user linked list The node pointer of the chain head;
所述数据读取模块,需要读取用户数据时,从内存的用户字典中查找用户指针,通过指针读取到用户链表中用户数据,如果存在则返回用户数据,如果不存在则从数据库读取后插入到1代用户链表的头部,并存储指针到用户字典中。The data reading module, when user data needs to be read, looks up the user pointer from the user dictionary in the internal memory, reads the user data in the user linked list through the pointer, returns the user data if it exists, and reads it from the database if it does not exist Then insert it into the head of the first-generation user linked list, and store the pointer in the user dictionary.
用户链表存储数据时,如果用户链表总长度大于预设长度值,则从用户链表的链尾开始,从1代用户链表开始向3代用户链表移动,移除设定数量的用户数据。When the user linked list stores data, if the total length of the user linked list is greater than the preset length value, start from the end of the user linked list, move from the 1st generation user linked list to the 3rd generation user linked list, and remove the set amount of user data.
所述数据读取模块的实现方式进一步具体为:读取用户数据时,优先从用户字典map中查找数据,如果存在则返回用户数据,如果不存在则从数据库读取用户数据后插入到1代用户链表的头部,并存储指针到用户字典map中,其中预设长度值是10000,即默认只存储10000个活跃用户在内存中的数据,如果用户链表总长度大于10000,则从链表尾部开始,通过用户链表结构的pre逐一向左进行前进,移除尾部开始的最后100个用户元素,这样代数越高、位置越靠左的用户更容易被保存在内存数据中。The implementation of the data reading module is further specifically: when reading user data, first look up data from the user dictionary map, if it exists, return the user data, if it does not exist, read the user data from the database and insert it into the first generation The head of the user linked list, and store pointers to the user dictionary map, where the preset length value is 10000, that is, only store the data of 10000 active users in memory by default, if the total length of the user linked list is greater than 10000, start from the end of the linked list , move forward one by one to the left through the pre of the user linked list structure, and remove the last 100 user elements starting from the tail, so that users with higher algebra and positions further to the left are more likely to be stored in memory data.
总之,本发明使用用户分代的思想,把用户通过不同的业务行为进行分代,并通过前后指针相连,使其形成一个分代的链表,链表从左往右形成一个活跃度的递减趋势,如果内存不足,要移除内存中的用户数据,则从最右边的链尾起开始移除。这样可以保证活跃用户更可能被保存下来。In short, the present invention uses the idea of user generation to divide users into generations through different business behaviors, and connects the front and back pointers to form a generational linked list, and the linked list forms a decreasing trend of activity from left to right. If the memory is insufficient, to remove the user data in the memory, start removing from the end of the rightmost chain. This ensures that active users are more likely to be saved.
以上所述仅为本发明的较佳实施例,凡依本发明申请专利范围所做的均等变化与修饰,皆应属本发明的涵盖范围。The above descriptions are only preferred embodiments of the present invention, and all equivalent changes and modifications made according to the scope of the patent application of the present invention shall fall within the scope of the present invention.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211294605.7A CN115563174A (en) | 2022-10-21 | 2022-10-21 | Method and system for managing user hot spot data in memory |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211294605.7A CN115563174A (en) | 2022-10-21 | 2022-10-21 | Method and system for managing user hot spot data in memory |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN115563174A true CN115563174A (en) | 2023-01-03 |
Family
ID=84746278
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202211294605.7A Pending CN115563174A (en) | 2022-10-21 | 2022-10-21 | Method and system for managing user hot spot data in memory |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN115563174A (en) |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101620618A (en) * | 2009-07-24 | 2010-01-06 | 中兴通讯股份有限公司 | Method and device for maintaining data stored in memory |
| US20110246503A1 (en) * | 2010-04-06 | 2011-10-06 | Bender Michael A | High-Performance Streaming Dictionary |
| CN102411632A (en) * | 2011-12-27 | 2012-04-11 | 北京人大金仓信息技术股份有限公司 | Chain table-based memory database page type storage method |
| CN102663096A (en) * | 2012-04-11 | 2012-09-12 | 北京像素软件科技股份有限公司 | Method for reading data based on data cache technology |
| CN112947856A (en) * | 2021-02-05 | 2021-06-11 | 彩讯科技股份有限公司 | Memory data management method and device, computer equipment and storage medium |
-
2022
- 2022-10-21 CN CN202211294605.7A patent/CN115563174A/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101620618A (en) * | 2009-07-24 | 2010-01-06 | 中兴通讯股份有限公司 | Method and device for maintaining data stored in memory |
| US20110246503A1 (en) * | 2010-04-06 | 2011-10-06 | Bender Michael A | High-Performance Streaming Dictionary |
| CN102411632A (en) * | 2011-12-27 | 2012-04-11 | 北京人大金仓信息技术股份有限公司 | Chain table-based memory database page type storage method |
| CN102663096A (en) * | 2012-04-11 | 2012-09-12 | 北京像素软件科技股份有限公司 | Method for reading data based on data cache technology |
| CN112947856A (en) * | 2021-02-05 | 2021-06-11 | 彩讯科技股份有限公司 | Memory data management method and device, computer equipment and storage medium |
Non-Patent Citations (1)
| Title |
|---|
| 王坚等: "《MySQL数据库原理及应用》", 31 January 2021, 机械工业出版社, pages: 108 - 109 * |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US6571244B1 (en) | Run formation in large scale sorting using batched replacement selection | |
| US8661006B1 (en) | Data file management system and method for browsers | |
| JP3554459B2 (en) | Text data registration search method | |
| US20040205044A1 (en) | Method for storing inverted index, method for on-line updating the same and inverted index mechanism | |
| CN103140840B (en) | Data management method and device | |
| CN114780530B (en) | Time series data storage method and system based on LSM tree key-value separation | |
| Huiying et al. | An intelligent algorithm of data pre-processing in Web usage mining | |
| CN102314485A (en) | Method and device for adding, searching and deleting hash table | |
| CN113934713B (en) | Order data indexing method, system, computer device and storage medium | |
| CN105912687A (en) | Mass distributed database memory cell | |
| CN114428776B (en) | Index partition management method and system for time series data | |
| JP3024619B2 (en) | File management method | |
| CN114625713A (en) | Metadata management method and device in storage system and storage system | |
| US20110179013A1 (en) | Search Log Online Analytic Processing | |
| TWI397060B (en) | Object-oriented storage device disk configuration method | |
| CN109299143B (en) | Knowledge fast indexing method of data interoperation test knowledge base based on Redis cache | |
| CN100399338C (en) | A data record processing method | |
| CN114595066B (en) | Processing method and device for reserved memory, electronic equipment and medium | |
| CN115563174A (en) | Method and system for managing user hot spot data in memory | |
| CN111752941A (en) | Data storage method, data access method, data storage device, data access device, server and storage medium | |
| US7966333B1 (en) | User segment population techniques | |
| US6885624B1 (en) | Methods for recording data to optical media | |
| JP2006092409A (en) | Complex database retrieval system, complex database retrieval method, and program therefor | |
| CN118796859A (en) | A database access method and device based on MyBatis framework | |
| CN114490562A (en) | Ceph distributed object storage directory retrieval method and device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |