CN106547603B - Method and device for reducing garbage recovery time of golang language system - Google Patents
Method and device for reducing garbage recovery time of golang language system Download PDFInfo
- Publication number
- CN106547603B CN106547603B CN201510613659.9A CN201510613659A CN106547603B CN 106547603 B CN106547603 B CN 106547603B CN 201510613659 A CN201510613659 A CN 201510613659A CN 106547603 B CN106547603 B CN 106547603B
- Authority
- CN
- China
- Prior art keywords
- memory space
- hash
- elements
- hash bucket
- bucket
- 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.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 47
- 238000011084 recovery Methods 0.000 title claims abstract description 14
- 230000006870 function Effects 0.000 claims description 24
- 238000004064 recycling Methods 0.000 claims description 11
- 230000011218 segmentation Effects 0.000 claims description 5
- 230000008901 benefit Effects 0.000 abstract description 5
- 230000008569 process Effects 0.000 description 12
- 238000010586 diagram Methods 0.000 description 11
- 238000012545 processing Methods 0.000 description 6
- 239000000725 suspension Substances 0.000 description 6
- 230000007246 mechanism Effects 0.000 description 4
- 230000004044 response Effects 0.000 description 3
- 238000004590 computer program Methods 0.000 description 2
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000018109 developmental process Effects 0.000 description 1
- 239000006185 dispersion Substances 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a method and a device for reducing garbage recovery time of a golang language system, and relates to the technical field of computers. The method comprises the following steps: allocating a continuous memory space for each hash bucket in the hash table; storing each element corresponding to the hash bucket in the continuous memory space; when garbage collection is performed on the hash table, elements in each hash bucket are released once. The method and the device have the advantages that the elements under the same bucket can be released at one time, the number of released objects is greatly reduced, the releasing efficiency is improved, the GC pause time is reduced, and the influence of GC pause on external access requests is reduced.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for reducing garbage recovery time of a golang language system.
Background
The Golang language is an open source project developed by Google, one of the purposes of which is to improve the programming efficiency of developers. The Golang language has flexible, concise, clear and efficient grammar, the concurrency characteristic of the Golang language can be conveniently used for multi-core processor and network development, and meanwhile, a flexible and novel type system can be conveniently used for compiling a modular system. go can compile fast, has automatic recovery function of rubbish memory simultaneously to still support the runtime reflection. Go is an efficient, static type, but has a system level syntax that characterizes the dynamic type of the interpreted language.
In the prior art, when a system is designed through a golang language, a GC (garbage collection) mechanism can be designed, and the GC mechanism can be used for recovering unneeded resources, namely releasing objects of unneeded elements; when the GC mechanism is executed, the system will pause, and there will be a GC pause time for the system. Under the architecture of the golang language, each element is recorded by using map (mapping), and when the map records the elements of the hash table, namely when key and value key pairs are recorded, the key and value are recorded in one object. In the system designed by the golang language, if a GC (garbage collection) mechanism of the system judges that the elements recorded by the map are no longer needed and resources need to be collected, all objects under the map need to be released.
However, since the system performs garbage collection, if there are too many objects, the release process is very long, and the GC pause time is also very long. Therefore, for the on-line system requiring short response time, the long GC pause time in the prior art makes the system unable to respond to the access request in time, and also makes the user wait for a long time, which reduces the system friendliness.
Disclosure of Invention
In view of the above problems, the present invention has been made to provide an apparatus for reducing garbage collection time of a golang language system and a corresponding method for reducing garbage collection time of the golang language system, which overcome or at least partially solve the above problems.
According to an aspect of the present invention, there is provided a method for reducing garbage collection time of a golang language system, comprising:
allocating a continuous memory space for an object in each hash bucket of the hash table;
storing each element corresponding to the hash bucket in the continuous memory space;
when garbage collection is performed on the elements, objects in each hash bucket are released once.
Preferably, the allocating a continuous memory space for an object in each hash bucket of the hash table includes:
generating an object for each hash bucket of the hash table, and storing an element pointer in the hash bucket;
allocating a continuous memory space and pointing the element pointer to the continuous memory space.
Preferably, the allocating a continuous memory space for an object in each hash bucket of the hash table includes:
in each hash bucket of the hash table, a continuous memory space is allocated to an object through slice.
Preferably, the allocating a continuous memory space for an object through slice in each hash bucket of the hash table includes:
initializing slice slices through a make function to obtain an array memory space; the array memory space includes N consecutive segments.
Preferably, the storing each element corresponding to the hash bucket in the continuous memory space includes:
when the number of the segments obtained by initialization is larger than or equal to the number N of the elements of the hash bucket, storing the elements corresponding to the hash bucket into the segments one by one;
and when the number of the segments obtained by initialization is smaller than the number N of the elements of the hash bucket, adding new segments one by one through an apend function and storing the elements after storing the last segment in the initialized segments.
Preferably, the elements include key and value key-value pairs.
Preferably, the releasing the objects in each hash bucket once when performing garbage collection on the elements includes:
and when the garbage collection is carried out on each element, releasing the memory space corresponding to each hash bucket, and releasing the element pointer.
The invention discloses a device for reducing garbage recovery time of a golang language system, which comprises:
the continuous space distribution module is suitable for distributing a continuous memory space for each hash bucket of the hash table;
the element storage module is suitable for storing each element corresponding to the hash bucket in the continuous memory space;
and the recycling module is suitable for releasing the objects in each hash bucket once when garbage recycling is carried out on each element.
Preferably, the contiguous space allocation module comprises:
a pointer storage submodule adapted to generate an object for each hash bucket of the hash table and to store element pointers within the hash buckets;
and the space allocation submodule is suitable for allocating a continuous memory space and pointing the element pointer to the continuous memory space.
Preferably, the contiguous space allocation module comprises:
and the segment space distribution submodule is suitable for distributing a continuous memory space for an object through a slice in each hash bucket of the hash table.
Preferably, the slicing space allocation sub-module includes:
the initial segmentation space distribution submodule is suitable for initializing slice slices through a make function to obtain an array memory space; the array memory space includes a plurality of consecutive segments.
Preferably, the element storage module includes:
the first storage module is suitable for storing the elements corresponding to the hash bucket into the segments one by one when the number of the segments obtained by initialization is more than or equal to the number N of the elements of the hash bucket;
and the second storage module is suitable for adding new segments one by one through an apend function and storing the elements after the last segment in the initialized segments is stored when the number of the segments obtained by initialization is smaller than the number N of the elements of the hash bucket.
Preferably, the elements include key and value key-value pairs.
Preferably, the recycling module comprises:
and the releasing submodule is suitable for releasing the memory space corresponding to each hash bucket and releasing the element pointer when the garbage recovery is carried out on each element.
According to the method and the device for reducing the garbage collection time of the golang language system, for the hash table which needs to be used, a continuous memory space is constructed by taking the bucket (hash bucket) of the hash table as an object in the server system constructed based on the golang language, and then the elements in the hash table corresponding to the bucket are stored into the continuous memory space one by one, so that when the system needs to execute GC, because a plurality of elements are in the continuous memory space of one object, the release of the elements only needs to be carried out once for the bucket, thereby solving the problems that in the prior art, when the elements are stored by adopting map, the object needs to be created for the key and value of each element, the number of the objects is extremely large, and when the system executes GC, the pause time of the GC is very long due to the huge number of the released objects, and the processing of the system to the external access request is influenced, the method has the advantages that the elements under the same bucket can be released at one time, the number of released objects is greatly reduced, the releasing efficiency is improved, the GC pause time is reduced, and the influence of GC pause on external access requests is reduced.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 shows a flow diagram illustrating a method for reducing garbage collection time of a golang language system according to an embodiment of the present invention;
FIG. 1A illustrates an example of a logical architecture of a hash bucket;
fig. 2 shows a flow diagram illustrating a method for reducing garbage collection time of the golang language system according to an embodiment of the present invention;
FIG. 2A is a diagram illustrating the storage logic for an element according to an embodiment of the present invention;
FIG. 2B illustrates a logical diagram of the storage of map pairs elements;
fig. 3 shows a schematic structural diagram of an apparatus for reducing garbage collection time in the golang language system according to an embodiment of the present invention; and
fig. 4 shows a schematic structural diagram of an apparatus for reducing garbage collection time in the golang language system according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Example one
Referring to fig. 1, a flowchart of a method for reducing garbage collection time of a golang language system according to an embodiment of the present invention is shown, where the method specifically includes:
the embodiment of the invention constructs a system of the server by using the golang language.
Then for various data in the system, if a hash table is needed, the embodiment of the present invention does not execute the logic of storing the elements in the hash table in the map form originally in the golang language. Which in turn executes the logic of step 110 of the present invention.
In the embodiment of the present invention, when the elements in the hash table are stored, each element may be first allocated to each bucket (hash bucket), so that one bucket may correspondingly record one or more elements. When the number of elements is large, such as tens of millions, one bucket can record more elements.
As shown in fig. 1A, which is a schematic diagram of a logical architecture of a hash table corresponding to a bucket, elements in a hash table may be scattered in each bucket, and each bucket corresponds to multiple elements. The present invention is not limited to a specific dispersion algorithm for dispersing elements into respective buckets.
In the embodiment of the present invention, for a bucket, an object is generated, and a system needs to allocate a system resource, such as a memory space, to the object when generating the object, so that the present invention allocates a continuous memory space to the object. The contiguous memory space may be divided into a plurality of contiguous segments, each segment storing data of the same format. In the embodiment of the present invention, the size of the segment in the continuous memory space may be determined according to the data sizes of the key and the value, and in practical application, a numerical value of the size of the segment may be set, where the numerical value is greater than the maximum data size of each key + value.
Preferably, the allocating a continuous memory space for an object in each hash bucket of the hash table in step 110 includes:
a substep 111 of generating an object for each hash bucket of the hash table and storing element pointers in the hash bucket;
in actual application, an object is generated for each bucket, and element pointers are stored in the hash bucket.
Sub-step 112, allocating a contiguous memory space and pointing said element pointer to said contiguous memory space.
For the generated object, a memory space needs to be allocated, but in the embodiment of the present invention, a continuous memory space is allocated for the generated object, the continuous memory space may be divided into continuous segments, and then the element pointer × elements may be pointed to the memory space. Thus, when the system queries an element, the storage location of the element can be found by the element pointer.
for a bucket, since some elements in the hash table are scattered into the bucket by the scattering algorithm, the elements can be written into the continuous memory space one by one. Each element is written in one segment.
For the elements of the hash table, the elements exist as key-value key values, the key is obtained by calculating the source data by using a certain hash algorithm, and the value is the specific content required to be used in the source data. For example, if the source data is the score record "zhang san, 93", the "zhang san" may be hashed to obtain a key, and then the key is equal to "93".
Through the manner, in the embodiment of the invention, all key-value key value pairs of a bucket are taken as data in the object, instead of respectively generating the key object and allocating an independent memory space for recording in the prior map technology, and then generating the value object and allocating an independent memory space for recording. The embodiment of the invention greatly reduces the generated objects and the system overhead.
And 130, releasing the objects in each hash bucket once when garbage collection is carried out on each element.
During the operation of the server system, it may be necessary to release the temporarily unused resources, for example, the elements of the aforementioned hash table may be temporarily unused, or the elements may be expired, and then the resources occupied by the elements need to be recycled, i.e., the GC process is performed. In the embodiment of the invention, when the GC process is executed, for the elements of the hash table, as each element of a bucket is in an object, all the elements of the bucket can be released only by releasing the object once, and the key and the value of each element do not need to be released independently. After the release is completed, the GC execution of the system is completed, and the processing of the external access request is resumed.
In practice, since the system performs the GC process, the system needs to be suspended, and for a real-time online system, the shorter the GC suspension time is, the better, if the GC suspension time is long, the access to the server by the user is affected, for example, if the GC suspension time is long, the access request is sent to the server by the user when the GC suspension is started, if the GC suspension time is short, the response delay of the server to the access request is low, if the GC suspension time is long, the response delay of the server to the access request is long, and the user feels that the access request to the server is not processed for a long time.
In the prior art, the hash table in the system of the golang language is stored in the form of map, the map stores key-value key values in the hash table in the form of objects, and stores values in the form of objects, and each object allocates an independent memory space for the system, each object needs to be released once during release, each release needs time, and the release time of a large batch of objects is accumulated, which results in a long GC pause time, and a long processing delay of the system for external access requests.
In the embodiment of the invention, because the object does not need to be generated independently aiming at the key and the value of each element and the independent memory space is distributed for storing the key and the value, and a plurality of elements of one bucket are also stored in the continuous memory space of one object, the number of the objects is greatly reduced, when the GC is executed, one object is released to release a plurality of elements, the release time of each element of the hash table is greatly reduced, the GC pause time is reduced, and the processing delay of the system to the external access request is shortened.
Example two
Referring to fig. 1, a flowchart of a method for reducing garbage collection time of a golang language system according to an embodiment of the present invention is shown, where the method specifically includes:
the embodiment of the invention constructs a system of the server by using the golang language.
Then for various data in the system, if a hash table is needed, the embodiment of the present invention does not execute the logic of storing the elements in the hash table in the map form originally in the golang language. Which in turn executes the logic of step 110 of the present invention.
In the embodiment of the present invention, when the elements in the hash table are stored, each element may be first allocated to each bucket (hash bucket), so that one bucket may correspondingly record one or more elements. When the number of elements is large, such as tens of millions, one bucket can record more elements.
In the embodiment of the present invention, a slice is a dynamic underlying array, which is an underlying data structure type, and the prototype thereof is:
struct Slice{
byte*array;
uintgo len;
unitgo cap;}
slice includes three members: array is a bottom array which corresponds to a continuous memory space, the bottom array can be divided into N sections, and each section stores one element; len is the number of elements actually stored; cap is the total volume of the slice.
In the embodiment of the present invention, an object is generated for a bucket, and a system needs to allocate a memory space to the object when generating the object.
Preferably, the allocating a continuous memory space for an object through slice in each hash bucket of the hash table in step 210 includes:
substep 211, initializing slice through make function to obtain array memory space; the array memory space includes N consecutive segments.
In the embodiment of the present invention, the system may call a make function to initialize the slice, that is, determine how long the memory space is generated according to the array, len, and cap. The memory space includes N consecutive segments. Wherein N is an integer greater than 0. In the embodiment of the invention, if the value of cap is set, the bottom array with the corresponding number is initialized.
The make () function is a built-in function provided by the Golang language that can be used to flexibly create slice slices. For example, a slice with an initial element number of 5 is created, the initial value of the element is 0, and the code thereof is:
mySlice1:=make([]int,5)
in practical application, the embodiment of the present invention generates an object for each hash bucket of the hash table, stores an element pointer in the hash bucket, and then points the element pointer to a slice as to the aforementioned continuous memory space, i.e., the slice.
in the embodiment of the present invention, after a consecutive memory space is allocated to a bucket, for example, in the aforementioned bottom-layer array space, the elements of the bucket may be written into the consecutive memory space one by one.
In the embodiment of the present invention, the element pointer of the bucket is pointed to the slice. Fig. 2A is a schematic diagram illustrating storage of elements of a bucket according to an embodiment of the present invention, where an element pointer points to a continuous memory space, and the memory space stores the elements of the bucket.
For comparison, as shown in fig. 2B, which is an example of a storage structure of map to element, since key and value are both objects, the objects are all represented by Ei for convenience of description. In FIG. 2B, each object Ei has a forward pointer Pi1 and a backward pointer Pi2, so there are not only many objects in the map, but also many pointers. In the logic diagram of fig. 2A of the embodiment of the present invention, a plurality of elements have only one pointer, and the elements are in one object.
Preferably, the storing each element corresponding to the hash bucket in the continuous memory space includes:
a substep 221 of storing the elements corresponding to the hash bucket into the segments one by one when the number of the segments obtained by initialization is greater than or equal to the number N of the elements of the hash bucket;
as mentioned above, a slice is a dynamic array, and only an array memory space of a preset length may be initialized during initialization. For example, an array memory space storing 3 elements is initialized, i.e., the array memory space has 3 segments. If the bucket corresponds to 3 elements, the bucket is stored in an array memory space, and the 3 elements are directly written into each segment one by one.
And a substep 222 of adding new segments one by one through an apend function and storing the elements after storing the last segment in the initialized segments when the number of the initialized segments is smaller than the number N of the elements of the hash bucket.
If the bucket corresponds to 5 elements, the initialized length of the array memory space with 3 segments is not enough, a new segment needs to be dynamically added after the 3 rd segment, one of the new remaining 2 elements is written into the segment, and then a new segment is added after the 4 th segment, and the remaining 1 element is written into the segment. The function of adding new segments and writing elements is an apend function, and the function prototype is as follows: apend (slice [ ] T, elements.
In step 230, when garbage collection is performed on each element, the objects in each hash bucket are released once.
During the operation of the server system, it may be necessary to release the temporarily unused resources, for example, the elements of the aforementioned hash table may be temporarily unused, or the elements may be expired, and then the resources occupied by the elements need to be recycled, i.e., the GC process is performed. In the embodiment of the invention, when the GC process is executed, for the elements of the hash table, as each element of a bucket is in an object, all the elements of the bucket can be released only by releasing the object once, and the key and the value of each element do not need to be released independently. After the release is completed, the GC execution of the system is completed, and the processing of the external access request is resumed.
Preferably, the releasing the objects in each hash bucket once when performing garbage collection on each element includes:
in the substep 231, when performing garbage collection on each element, the memory space corresponding to each hash bucket is released, and the element pointer is released.
In the actual GC process, the release of the object is to release the memory space where the target data is located, and the pointer pointing to the memory space can be released accordingly to recycle the memory resource. In practice, the pointer may be set to NULL instead of being released, so as to avoid program crash.
In contrast, as shown in fig. 2B, map needs to process a large number of pointers in the GC process in addition to performing a large number of release processes, and the GC is paused for a long time.
According to the embodiment of the invention, because the object does not need to be separately generated for the key and the value of each element and the independent memory space is allocated for the key and the value of each element for storage, and a plurality of elements of a bucket are also stored in the continuous memory space of one object, the number of the objects is greatly reduced, and one bucket only has one pointer pointing to a slice, when GC is executed, the plurality of elements can be released by releasing one object, and only one pointer of the object is processed, so that the release time of each element of the hash table is greatly reduced, the GC pause time is reduced, and the processing delay of the system to the external access request is shortened.
EXAMPLE III
Referring to fig. 3, a schematic structural diagram of an apparatus for reducing garbage collection time in the golang language system according to an embodiment of the present invention is shown, where the apparatus may specifically include:
a continuous space allocation module 310, adapted to allocate, for each hash bucket of the hash table, a continuous memory space for the hash bucket;
an element storage module 320 adapted to store each element corresponding to the hash bucket in the contiguous memory space;
the recycling module 330 is adapted to release the objects in each hash bucket once when performing garbage recycling on the respective elements.
Preferably, the contiguous space allocation module comprises:
a pointer storage submodule adapted to generate an object for each hash bucket of the hash table and to store element pointers within the hash buckets;
and the space allocation submodule is suitable for allocating a continuous memory space and pointing the element pointer to the continuous memory space.
Example four
Referring to fig. 4, a schematic structural diagram of an apparatus for reducing garbage collection time in the golang language system according to an embodiment of the present invention is shown, where the apparatus may specifically include:
the continuous space allocating module 410 is adapted to allocate, for each hash bucket of the hash table, a continuous memory space for the hash bucket, and specifically may include:
the segment space allocating submodule 411 is adapted to allocate a continuous memory space for an object through slice in each hash bucket of the hash table.
An element storage module 420 adapted to store elements corresponding to the hash bucket in the contiguous memory space;
a reclamation module 430 adapted to release objects within each hash bucket once when performing garbage reclamation on the respective elements.
Preferably, the slicing space allocation sub-module includes:
the initial segmentation space distribution submodule is suitable for initializing slice slices through a make function to obtain an array memory space; the array memory space includes a plurality of consecutive segments.
Preferably, the element storage module includes:
the first storage module is suitable for storing the elements corresponding to the hash bucket into the segments one by one when the number of the segments obtained by initialization is more than or equal to the number N of the elements of the hash bucket;
and the second storage module is suitable for adding new segments one by one through an apend function and storing the elements after the last segment in the initialized segments is stored when the number of the segments obtained by initialization is smaller than the number N of the elements of the hash bucket.
Preferably, the elements include key and value key-value pairs.
Preferably, the recycling module comprises:
and the releasing submodule is suitable for releasing the memory space corresponding to each hash bucket and releasing the element pointer when the garbage recovery is carried out on each element.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement embodiments in accordance with the inventionReducing garbage of golang language system For recycling of timeSome or all of the functions of some or all of the components in the device. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.
The invention discloses A1 and a method for reducing garbage recovery time of a golang language system, which comprises the following steps:
allocating a continuous memory space for an object in each hash bucket of the hash table;
storing each element corresponding to the hash bucket in the continuous memory space;
when garbage collection is performed on the elements, objects in each hash bucket are released once.
A2, the method according to a1, wherein allocating a continuous memory space for an object in each hash bucket of the hash table comprises:
generating an object for each hash bucket of the hash table, and storing an element pointer in the hash bucket;
allocating a continuous memory space and pointing the element pointer to the continuous memory space.
A3, the method according to a1, wherein allocating a continuous memory space for an object in each hash bucket of the hash table comprises:
in each hash bucket of the hash table, a continuous memory space is allocated to an object through slice.
A4, according to the method in A3, the allocating a continuous memory space for an object through slice in each hash bucket of the hash table includes:
initializing slice slices through a make function to obtain an array memory space; the array memory space includes N consecutive segments.
A5, the storing elements corresponding to the hash buckets in the contiguous memory space according to the method of A4, comprising:
when the number of the segments obtained by initialization is larger than or equal to the number N of the elements of the hash bucket, storing the elements corresponding to the hash bucket into the segments one by one;
and when the number of the segments obtained by initialization is smaller than the number N of the elements of the hash bucket, adding new segments one by one through an apend function and storing the elements after storing the last segment in the initialized segments.
A6, the element comprising a key and value key-value pair according to the method of A1.
A7, the method of A2, wherein the releasing the objects in each hash bucket once when performing garbage collection on the elements comprises:
and when the garbage collection is carried out on each element, releasing the memory space corresponding to each hash bucket, and releasing the element pointer.
The invention discloses B8, a device for reducing garbage recovery time of a golang language system, which comprises:
the continuous space distribution module is suitable for distributing a continuous memory space for each hash bucket of the hash table;
the element storage module is suitable for storing each element corresponding to the hash bucket in the continuous memory space;
and the recycling module is suitable for releasing the objects in each hash bucket once when garbage recycling is carried out on each element.
B9, the apparatus of B8, the contiguous space allocation module comprising:
a pointer storage submodule adapted to generate an object for each hash bucket of the hash table and to store element pointers within the hash buckets;
and the space allocation submodule is suitable for allocating a continuous memory space and pointing the element pointer to the continuous memory space.
B10, the apparatus of B8, the contiguous space allocation module comprising:
and the segment space distribution submodule is suitable for distributing a continuous memory space for an object through a slice in each hash bucket of the hash table.
B11, the device according to B10, the cutting space distribution submodule comprises:
the initial segmentation space distribution submodule is suitable for initializing slice slices through a make function to obtain an array memory space; the array memory space includes a plurality of consecutive segments.
B12, the apparatus of B11, the element storage module comprising:
the first storage module is suitable for storing the elements corresponding to the hash bucket into the segments one by one when the number of the segments obtained by initialization is more than or equal to the number N of the elements of the hash bucket;
and the second storage module is suitable for adding new segments one by one through an apend function and storing the elements after the last segment in the initialized segments is stored when the number of the segments obtained by initialization is smaller than the number N of the elements of the hash bucket.
B13, the apparatus of B8, the element comprising a key and value key-value pair.
B14, the device according to B9, the recovery module comprising:
and the releasing submodule is suitable for releasing the memory space corresponding to each hash bucket and releasing the element pointer when the garbage recovery is carried out on each element.
Claims (14)
1. A method for reducing garbage collection time of a golang language system, comprising:
allocating a continuous memory space for an object in each hash bucket of the hash table;
storing each element corresponding to the hash bucket in the continuous memory space;
when garbage collection is performed on the elements, objects in each hash bucket are released once.
2. The method of claim 1, wherein allocating a contiguous memory space for an object in each hash bucket of the hash table comprises:
generating an object for each hash bucket of the hash table, and storing an element pointer in the hash bucket;
allocating a continuous memory space and pointing the element pointer to the continuous memory space.
3. The method of claim 1, wherein allocating a contiguous memory space for an object in each hash bucket of the hash table comprises:
in each hash bucket of the hash table, a continuous memory space is allocated to an object through slice.
4. The method of claim 3, wherein allocating a contiguous memory space for an object through slice in each hash bucket of the hash table comprises:
initializing slice slices through a make function to obtain an array memory space; the array memory space includes N consecutive segments.
5. The method of claim 4, wherein storing elements corresponding to the hash buckets in the contiguous memory space comprises:
when the number of the segments obtained by initialization is larger than or equal to the number N of the elements of the hash bucket, storing the elements corresponding to the hash bucket into the segments one by one;
and when the number of the segments obtained by initialization is smaller than the number N of the elements of the hash bucket, adding new segments one by one through an apend function and storing the elements after storing the last segment in the initialized segments.
6. The method of claim 1, wherein the elements comprise key and value key value pairs.
7. The method of claim 2, wherein the releasing the objects in each hash bucket once when performing garbage collection on the respective elements comprises:
and when the garbage collection is carried out on each element, releasing the memory space corresponding to each hash bucket and releasing the element pointer.
8. An apparatus for reducing garbage collection time of a golang language system, comprising:
the continuous space distribution module is suitable for distributing a continuous memory space for each hash bucket of the hash table;
the element storage module is suitable for storing each element corresponding to the hash bucket in the continuous memory space;
and the recycling module is suitable for releasing the objects in each hash bucket once when garbage recycling is carried out on each element.
9. The apparatus of claim 8, wherein the contiguous space allocation module comprises:
a pointer storage submodule adapted to generate an object for each hash bucket of the hash table and to store element pointers within the hash buckets;
and the space allocation submodule is suitable for allocating a continuous memory space and pointing the element pointer to the continuous memory space.
10. The apparatus of claim 8, wherein the contiguous space allocation module comprises:
and the segment space distribution submodule is suitable for distributing a continuous memory space for an object through a slice in each hash bucket of the hash table.
11. The apparatus of claim 10, wherein the segmentation space allocation submodule comprises:
the initial segmentation space distribution submodule is suitable for initializing slice slices through a make function to obtain an array memory space; the array memory space includes a plurality of consecutive segments.
12. The apparatus of claim 11, wherein the element storage module comprises:
the first storage module is suitable for storing the elements corresponding to the hash bucket into the segments one by one when the number of the segments obtained by initialization is more than or equal to the number N of the elements of the hash bucket;
and the second storage module is suitable for adding new segments one by one through an apend function and storing the elements after the last segment in the initialized segments is stored when the number of the segments obtained by initialization is smaller than the number N of the elements of the hash bucket.
13. The apparatus of claim 8, wherein the elements comprise key and value key value pairs.
14. The apparatus of claim 9, wherein the recovery module comprises:
and the releasing submodule is suitable for releasing the memory space corresponding to each hash bucket and releasing the element pointer when the garbage recovery is carried out on each element.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510613659.9A CN106547603B (en) | 2015-09-23 | 2015-09-23 | Method and device for reducing garbage recovery time of golang language system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510613659.9A CN106547603B (en) | 2015-09-23 | 2015-09-23 | Method and device for reducing garbage recovery time of golang language system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106547603A CN106547603A (en) | 2017-03-29 |
CN106547603B true CN106547603B (en) | 2021-05-18 |
Family
ID=58365272
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201510613659.9A Active CN106547603B (en) | 2015-09-23 | 2015-09-23 | Method and device for reducing garbage recovery time of golang language system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106547603B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109710542B (en) * | 2018-12-28 | 2021-03-16 | 北京像素软件科技股份有限公司 | Full N-way tree construction method and device |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101046755A (en) * | 2006-03-28 | 2007-10-03 | 郭明南 | System and method of computer automatic memory management |
CN101122885A (en) * | 2007-09-11 | 2008-02-13 | 腾讯科技(深圳)有限公司 | Data cache processing method, system and data cache device |
CN103678160A (en) * | 2012-08-30 | 2014-03-26 | 腾讯科技(深圳)有限公司 | Data storage method and device |
JP2014225077A (en) * | 2013-05-15 | 2014-12-04 | インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation | Method for managing object in computer, and program and system |
-
2015
- 2015-09-23 CN CN201510613659.9A patent/CN106547603B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101046755A (en) * | 2006-03-28 | 2007-10-03 | 郭明南 | System and method of computer automatic memory management |
CN101122885A (en) * | 2007-09-11 | 2008-02-13 | 腾讯科技(深圳)有限公司 | Data cache processing method, system and data cache device |
CN103678160A (en) * | 2012-08-30 | 2014-03-26 | 腾讯科技(深圳)有限公司 | Data storage method and device |
JP2014225077A (en) * | 2013-05-15 | 2014-12-04 | インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation | Method for managing object in computer, and program and system |
Non-Patent Citations (1)
Title |
---|
引入哈希桶的概念来实现一个哈希表;wangpengqi;《CSDN https://blog.csdn.net/wangpengqi/article/details/9716315》;20130802;全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN106547603A (en) | 2017-03-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Dukic et al. | Photons: Lambdas on a diet | |
JP5139987B2 (en) | Extensible metadata | |
US9996394B2 (en) | Scheduling accelerator tasks on accelerators using graphs | |
TWI574202B (en) | Memory management model and interface for new applications | |
CN110008009B (en) | Binding constants at runtime to improve resource utilization | |
TWI539280B (en) | Method for analyzing application not specifically designed to provide memory allocation informaion and extracting memory allocation information, and computer system and computer-readable storage medium thereof | |
JP6370218B2 (en) | MEMORY MANAGEMENT METHOD, COMPUTER SYSTEM, COMPUTER PROGRAM, AND STORAGE MEDIUM | |
US20170220393A1 (en) | Autonomous dynamic optimization of platform resources | |
KR20200135718A (en) | Method, apparatus, device and storage medium for managing access request | |
US11016886B2 (en) | Multi-ring shared, traversable, and dynamic advanced database | |
US20190377612A1 (en) | VCPU Thread Scheduling Method and Apparatus | |
JP6974510B2 (en) | Methods, devices, devices and media for processing data | |
CN103902369A (en) | Cooperative thread array granularity context switch during trap handling | |
Li et al. | A novel disk I/O scheduling framework of virtualized storage system | |
US20200272441A1 (en) | Systems and methods for mapping software applications interdependencies | |
CN106547603B (en) | Method and device for reducing garbage recovery time of golang language system | |
US8539461B2 (en) | Method for identifying memory of virtual machine and computer system thereof | |
CN108121602B (en) | Method for determining garbage collection trigger point, electronic equipment and storage medium | |
WO2017001900A1 (en) | A data processing method | |
Kushsairy et al. | Embedded vision: Enhancing embedded platform for face detection system | |
US20230266992A1 (en) | Processor for managing resources using dual queues, and operating method thereof | |
US10521155B2 (en) | Application management data | |
US20240193016A1 (en) | Multiple processes sharing gpu memory objects | |
US20230214196A1 (en) | Method of rebinding computing unit in heterogeneous computing clouds and apparatus thereof | |
WO2022000405A1 (en) | Methods and apparatus to deduplicate duplicate memory in a cloud computing environment |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
TR01 | Transfer of patent right |
Effective date of registration: 20240113 Address after: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park) Patentee after: BEIJING QIHOO TECHNOLOGY Co.,Ltd. Address before: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park) Patentee before: BEIJING QIHOO TECHNOLOGY Co.,Ltd. Patentee before: Qizhi software (Beijing) Co.,Ltd. |
|
TR01 | Transfer of patent right |