CN106610996B - Hot dictionary switching method and device - Google Patents

Hot dictionary switching method and device Download PDF

Info

Publication number
CN106610996B
CN106610996B CN201510698232.3A CN201510698232A CN106610996B CN 106610996 B CN106610996 B CN 106610996B CN 201510698232 A CN201510698232 A CN 201510698232A CN 106610996 B CN106610996 B CN 106610996B
Authority
CN
China
Prior art keywords
dictionary
hot
hot dictionary
state change
state
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
Application number
CN201510698232.3A
Other languages
Chinese (zh)
Other versions
CN106610996A (en
Inventor
韩中腾
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Qizhi Software Beijing Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd, Qizhi Software Beijing Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201510698232.3A priority Critical patent/CN106610996B/en
Publication of CN106610996A publication Critical patent/CN106610996A/en
Application granted granted Critical
Publication of CN106610996B publication Critical patent/CN106610996B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9535Search customisation based on user profiles and personalisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Stored Programmes (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention discloses a hot dictionary switching method and device, and relates to the technical field of computers. The method comprises the following steps: monitoring whether the state of each hot dictionary changes; and if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change in a hot mode. The invention solves the problem that the hot dictionary in the latest state can be used only by restarting the service, and obtains the hot dictionary which can be used by each service without restarting the service, thereby avoiding the suspension of the on-line service and ensuring that a user can not interrupt the access to the service.

Description

Hot dictionary switching method and device
Technical Field
The invention relates to the technical field of computers, in particular to a hot dictionary switching method and device.
Background
With the development of computer technology, more and more online services provide network resources for users. These online services may use dictionaries that are relatively independent of the service, and the service first loads the contents of the dictionary into the service's memory and then uses it. Such as, for example, a black/white list, index words, etc. In practical applications, the dictionaries may change at any time, for example, the black/white list may change continuously with time, and therefore, some services requiring the dictionaries need to update the currently used dictionaries to the latest dictionaries.
In the prior art, when the dictionary changes, if a service needs to use a new dictionary, the service needs to be stopped and then restarted, so that the new dictionary can be loaded. For the online service, the scheme is equivalent to interruption, and in the restarting process, an external user cannot access any function of the service, so that the access of the user to the service is delayed.
Disclosure of Invention
In view of the above, the present invention has been made to provide a hot dictionary switching apparatus and a corresponding hot dictionary switching method that overcome or at least partially solve the above-mentioned problems.
According to an aspect of the present invention, a hot dictionary switching method is disclosed, comprising:
monitoring whether the state of each hot dictionary changes;
and if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change in a hot mode.
Preferably, the step of hot-updating the hot dictionary currently used by each target service to the hot dictionary after the state change includes:
and the hot dictionary currently used by each target service is thermally updated to the hot dictionary after the state is changed in a mode of monitoring and executing multitask parallel through the thread pool.
Preferably, the step of monitoring whether the state of each thermal dictionary changes includes:
and monitoring whether the state of each hot dictionary changes or not by calling the inotify API.
Preferably, the step of monitoring whether the state of each thermal dictionary changes by calling the inotify API includes:
for each hot dictionary, initializing a file change monitor through an initialization function inotify _ init () in the inotify API, and returning a file descriptor;
adding a function inotify _ add _ watch () through a file change monitor in an inotify API, and registering a file change monitor for the file descriptor; and returning a state change message of the hot dictionary after the state change event of the hot dictionary is monitored by the file change monitor.
Preferably, the hot updating the hot dictionary currently used by each target service to the hot dictionary after the state change includes:
receiving, by a thread pool, a state change message of the thermal dictionary;
and according to the state change message, utilizing each working thread in the thread pool, and aiming at the target service needing to use the thermal dictionary, thermally updating the thermal dictionary currently used by the target service to the thermal dictionary after the state change.
Preferably, the monitoring whether the state of each thermal dictionary changes includes:
whether each hot dictionary is updated or not is monitored.
Preferably, the step of hot updating the currently used thermal dictionary to the thermal dictionary after the state change includes:
setting the loading record of the target service to the hot dictionary to be empty, and triggering a loading function for reloading the hot dictionary;
and acquiring the hot dictionary after the state change through the loading function and loading.
According to another aspect of the present invention, there is also disclosed a hot dictionary switching apparatus, comprising:
the monitoring module is suitable for monitoring whether the state of each hot dictionary changes;
and the hot dictionary switching module is suitable for hot updating the hot dictionary currently used by each target service into the hot dictionary after the state change if the state change of the hot dictionary is monitored.
Preferably, the hot dictionary switching module includes:
and the thread pool monitoring module is suitable for carrying out monitoring and executing multitask parallel mode through the thread pool to thermally update the thermal dictionary currently used by each target service into the thermal dictionary after the state is changed.
Preferably, the monitoring module comprises:
and the interface monitoring module is suitable for monitoring whether the state of each hot dictionary changes or not by calling the inotify API.
Preferably, the interface listening module includes:
the file descriptor acquisition module is suitable for initializing a file change monitor through an initialization function inotify _ init () in the inotify API and returning a file descriptor for each hot dictionary; the file change monitor adding module is suitable for adding a function inotify _ add _ watch () through a file change monitor in an inotify API and registering a file change monitor for the file descriptor;
and the return module is suitable for returning the state change message of the hot dictionary after the state change event of the hot dictionary is monitored by the file change monitor.
Preferably, the hot dictionary switching module includes:
a message receiving module adapted to receive a state change message of the thermal dictionary by a thread pool;
and the first switching module is suitable for utilizing each working thread in the thread pool according to the state change message and aiming at the target service needing to use the hot dictionary, and thermally updating the hot dictionary currently used by the target service into the hot dictionary after the state change.
Preferably, the monitoring module comprises:
whether each hot dictionary is updated or not is monitored.
Preferably, the hot dictionary switching module includes:
the unloading module is suitable for setting the loading record of the target service to the hot dictionary to be empty and triggering a loading function for reloading the hot dictionary;
and the reloading module is suitable for acquiring the hot dictionary with the changed state and loading the hot dictionary through the loading function.
According to another aspect of the present invention, there is also disclosed an electronic device including:
a memory and a processor;
the memory is used for storing executable codes;
the processor is configured to execute the executable code, the executable code performing a method comprising:
monitoring whether the state of each hot dictionary changes;
and if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change in a hot mode.
According to the hot dictionary switching method and device, whether the state of each hot dictionary changes or not can be monitored, if the state of one hot dictionary changes, the hot dictionary currently used by each target service is updated to the hot dictionary after the state changes, the problem that the hot dictionary in the latest state can be used only when the service needs to be restarted is solved, the hot dictionary used by each service can be updated without restarting the service is obtained, the suspension of the online service is avoided, and a user can access the service without interruption.
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 is a flow chart diagram illustrating a hot dictionary switching method according to an embodiment of the present invention;
FIG. 1A illustrates a thread pool work model according to one embodiment of the invention;
FIG. 2 is a flow chart diagram illustrating a hot dictionary switching method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a hot dictionary switching apparatus according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a hot dictionary switching apparatus according to an embodiment of the present invention;
fig. 5 shows a schematic structural diagram of an electronic device according to an embodiment of the 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 hot dictionary switching method according to an embodiment of the present invention is shown, which may specifically include:
step 110, monitoring whether the state of each thermal dictionary changes;
in an embodiment of the present invention, the hot dictionary is a basic data support module, which provides data support for a service that needs to use the hot dictionary, and the hot dictionary includes hot dictionaries such as a black/white list, advertisement search terms, and the like.
The target service can be understood as a process of an application, such as an online antivirus service, an advertisement search service, and the like. The client can access the service to obtain the data it needs. Such as a hot dictionary switching service, etc.
In practical applications, there may be many hot dictionaries, such as 100 hot dictionaries, and different kinds of hot dictionaries manage different needs or different kinds of words. Such as a black list hot dictionary, a white list hot dictionary, a hot dictionary of advertising bid words, and so forth.
If the state of the hot dictionary may be changing continuously, and then after the state of the hot dictionary changes, the data currently used by each service belongs to an expired state, which is inaccurate, then the embodiment of the present invention needs to monitor whether the state of the hot dictionary changes, and if the state of the hot dictionary changes, step 120 is performed.
Preferably, the monitoring whether the state of each thermal dictionary changes includes:
substep 111, monitoring whether each hot dictionary is updated.
After the hot dictionary is updated, the state of the hot dictionary changes. For example, for the hot dictionary of advertisement bid term, if each advertiser purchases different advertisement bid terms in the advertisement platform, the state of the hot dictionary changes due to the new advertisement bid term, the new attribute of the original advertisement bid term (the attribute new price, the corresponding advertiser, etc.). Or the technician in the background controls the update of the hot dictionary, the state of the hot dictionary changes. Wherein the updating comprises operations of modifying, adding, deleting and the like of the hot dictionary.
For the service, the data in the hot dictionary needs to be loaded into the memory of the service, the data is only the loaded data of the hot dictionary at the current moment, and the data after the update of the hot dictionary cannot be used. For example, if the target service loads the data of the hot dictionary at 10:00:00 of 2015-10-15 and the hot dictionary is updated at 10:10:00, then the data of the hot dictionary loaded at 10:00:00 and used by target service a cannot be used for the updated data of the hot dictionary. Therefore, to avoid this situation, step 120 is entered.
It can be understood that the hot dictionary is relatively independent from the service, the hot dictionary can be understood as a library file, the hot dictionary provides data support for the service, the content in the current library file of the service is loaded into the memory of the service when the service loads the hot dictionary, the update of the hot dictionary is independent from the data loaded by the service, and the hot dictionary is updated independently. Thus, for one or more services, after the hot dictionary used by the service is updated, the service needs to reload the data in the new hot dictionary to ensure the timeliness of the data.
Preferably, in another embodiment of the present invention, the step of monitoring whether the status of each thermal dictionary changes includes:
and a substep 112 of monitoring whether the state of each thermal dictionary changes by calling the inotify API.
For the monitoring of the hot dictionaries, if a thread is created for each hot dictionary, the thread polls the time stamp form of the monitoring hot dictionary to obtain the state of the hot dictionary and determine the changed and unchanged results. The state change result of the thermal dictionary needs to be obtained continuously, so that the overhead is high and the resource occupation is high. In order to further solve the problem, the embodiment of the present invention calls an inotify API to monitor whether the state of each hot dictionary changes, and monitors the change of the file state of the hot dictionary at the kernel layer. The Inotify API (Inotify Application Program Interface), which is a Linux kernel feature, monitors file system events and issues relevant event notifications in time.
In the embodiment of the invention, for the monitoring request task of one hot dictionary, each working thread of the thread pool calls the Inotify API, the Inotify API monitors the state change of the hot dictionary, and the state change result is returned to the result queue of the thread pool.
Further, the step of monitoring whether the state of each thermal dictionary changes by calling the inotify API includes:
substep S11, for each hot dictionary, initializing the file change monitor through an initialization function inotify _ init () in the inotify API, and returning a file descriptor;
in the embodiment of the invention, when a worker thread calls an inotify API for a hot dictionary first, an initialization function inotify _ init () in the worker thread is called to create an inotify instance in a kernel, a file change monitor is initialized, if the file change monitor succeeds, a file descriptor of the hot dictionary is returned, and if the file change monitor fails, the file descriptor of the hot dictionary is returned to-1.
A substep S12, adding a function inotify _ add _ watch () through a file change monitor in the inotify API, and registering a file change monitor for the file descriptor;
after initializing the file change monitor by the initialization function inotify _ init () in the inotify API, the file change monitor is not yet set with a monitoring object, and then after initializing the file change monitor and successfully acquiring the file descriptor of the thermal dictionary, the inotify _ add _ watch () in the inotify API is called to obtain the file descriptor registered by the file change monitor in the sub-step S11, so as to provide the file change monitor with information including the path name of the thermal dictionary file and the list of related events to be monitored.
In the embodiment of the present invention, the list of related events to be monitored includes a file update event. Because all events of update operations such as addition, deletion, modification and the like of files are all events, the embodiment of the invention only needs to monitor the files of the hot dictionary by the file change monitor in the kernel layer and then inform the monitoring result to the file change result of the hot dictionary of the thread pool of the application layer.
Of course, in practical applications, the related events may directly include events such as addition, deletion, and update to the file, and then the file change monitor may directly monitor the events to determine the change status of the hot dictionary.
In practical applications, after the file change monitor is added, the read () function may be called to obtain the event information in the above list from the descriptor.
And a substep S13, returning a status change message of the hot dictionary after monitoring the hot dictionary status change event through the file change monitor.
After the file change monitor monitors the events in the list, a state change message of the hot dictionary is generated according to the event information of the hot dictionary. Such as monitoring a modification event of a file at the kernel layer, then a state change message of the thermal dictionary is generated and returned to the thread pool of the application layer.
In practical application, the thread pool adds request tasks to a request queue (RequestQueue) by a request adding method (putRequest) based on the production state changed message, wherein each request task is used for carrying out hot updating on a hot dictionary used by a target service.
And step 120, if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change in a hot mode.
In the embodiment of the invention, for each monitored thermal dictionary, if the state of one or more thermal dictionaries is changed, the thermal dictionary currently used by each target service can be updated to the thermal dictionary after the state is changed.
In practical applications, the above hot update may be implemented in various ways, for example, through a require function of the Lua language, and data in a file of the hot dictionary currently loaded by the target service may be replaced with new data in the file of the hot dictionary. Of course, other languages may be used to implement the hot update, and the present invention is not limited thereto.
Preferably, in another embodiment of the present invention, the step of monitoring whether the status of each thermal dictionary changes includes:
and a substep 121, performing hot updating on the hot dictionary currently used by each target service to the hot dictionary after the state change by monitoring and executing the multitask parallel mode through the thread pool.
In practical applications, because there are multiple hot dictionaries, a thread may be created for each hot dictionary to perform a process of hot updating the hot dictionary currently used by each target service to the hot dictionary after the state change. For example, there are 100 hot dictionaries, 100 threads can be created to perform the above hot update process.
However, in the above manner, since one thread needs to be created for each hot dictionary, the threads are independent, which is high in overhead and inconvenient for uniform management of the threads.
In order to solve the problems of large overhead and inconvenience in unified management caused by the fact that a thread is created for each hot dictionary, the embodiment of the invention creates a thread pool, and the hot dictionary currently used by each target service is updated to the hot dictionary after the state is changed in a mode of monitoring and executing multitask parallel through the thread pool.
In practical applications, a typical thread pool should include the following parts:
1. and the thread pool manager (ThreadPool) is used for starting, stopping and managing the thread pool.
2. Work thread (WorkThread), a thread in a thread pool.
3. And a request interface (WorkRequest) for creating a request object for the work thread to schedule the execution of the task.
4. Request queue (RequestQueue) for storing and retrieving requests
5. A result queue (ResultQueue) for storing results returned after the request is executed
FIG. 1A, which is a thread pool work model. The thread pool manager (ThreadPool) adds a request task to a request queue (RequestQueue) by a method (putRequest) for adding a request, wherein the request task needs to realize a request interface (WorkRequest) in advance, namely a transfer work function, a parameter, a result processing function and an exception processing function. The thread pool manager (ThreadPool) then initializes a number of work threads (WorkThread) and adds or deactivates the work threads during subsequent use. The above-mentioned every work thread (WorkThread) looks over the request queue (RequestQueue) constantly through the polling way, as long as there is a request task in the request queue (RequestQueue), will extract the request task, carry out, the work thread (WorkThread) puts the execution result into the result queue (ResultQueue). Then, the thread pool manager calls a method (poll) to check whether the result queue (resultQueue) has a value, if so, the result queue is taken out, and a corresponding result processing function is called to execute. In the above process, the worker thread obtains the requested task by polling the request queue (RequestQueue), and the thread pool manager (ThreadPool) obtains the execution result by looking up the result queue (ResultQueue).
Preferably, the hot updating the hot dictionary currently used by each target service to the hot dictionary after the state change includes:
a substep 122 of receiving, by a thread pool, a state change message of the thermal dictionary;
and a substep 123 of hot updating the hot dictionary currently used by the target service to the hot dictionary after the state change for the target service needing to use the hot dictionary by using each working thread in the thread pool according to the state change message.
In the embodiment of the invention, a thread pool manager (ThreadPool) creates a hot update request task for the state change message of the hot dictionary of each hot dictionary, then puts the hot update request task into a request queue (RequestQueue), and creates a certain number of working threads. Each worker thread then polls the queue, extracts the hot update request task execution from it, and places the results of its execution (e.g., status unchanged, status changed) in a result queue (resultQueue). And the thread pool manager (ThreadPool) calls a method (poll) to check whether the result queue (resultQueue) has a value, if so, the result queue is taken out, and a corresponding result processing function is called to execute.
Of course, in practical applications, different target services may use different thermal dictionaries, and in the embodiment of the present invention, a corresponding table of the target service and the thermal dictionary may be configured in advance, where the table records the thermal dictionary and the process/thread name of the target service that needs to use the thermal dictionary, such as the table (one):
heat dictionary Targeted services
Blacklist dictionary Target service 1, target service 3, target service 5
White list dictionary Target service 1, target service 3, target service 5
Advertisement bidding word dictionary Target service 1, target service 2, target service 4
Watch 1
And then, after monitoring the state change of a hot dictionary, notifying the corresponding target service according to the table to hot update the data of the hot dictionary in use to the data of the hot dictionary after the state change.
Preferably, the step of thermally updating the currently used thermal dictionary to the thermal dictionary after the state change includes:
substep 124, setting the loading record of the target service to the hot dictionary to be empty, and triggering a loading function for reloading the hot dictionary;
and a substep 125, obtaining the hot dictionary after the state change through the loading function and loading.
In practical applications, the embodiment of the present invention may set a hot update logic in a service, and the hot update logic may set a load record of the hot dictionary to be empty by the target service after receiving a notification of a change of state of the hot dictionary used by the hot update logic, that is, set a load record of a file of the hot dictionary to be empty in a registration list of the target service. Then it is necessary for the target service to reload the hot dictionary since the load record for the hot dictionary is set to null.
For example, for the aforementioned require function, the target service may determine in the registry [ "_ load" ] table whether an overheat dictionary has been LOADED. If the hot dictionary is already LOADED, it is recorded in the registry [ "_ LOADED" ] table, and then calling the require function at this time will not be loading the hot dictionary because it is already recorded.
In the embodiment of the present invention, the registered value of the hot dictionary corresponding to the notification that the state has changed in the registration [ "_ load" ] table is set to null, which indicates that the hot dictionary has not been LOADED, then the require function is called, and the hot dictionary after the state change is LOADED from the specified storage location, so that the process of hot updating the currently used hot dictionary into the hot dictionary after the state change can be realized.
Of course, in the embodiment of the present invention, a thread pool may also be created by the target service itself, and various hot dictionaries used by the target service itself may be updated in a hot manner.
The embodiment of the invention can monitor whether the state of each hot dictionary changes or not, and if the state change of one hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change, thereby solving the problem that the hot dictionary in the latest state can be used only when the service needs to be restarted, and obtaining the hot dictionary used by each service which can be updated without restarting the service, thereby avoiding the suspension of the online service and ensuring that a user can not interrupt the access to the service.
Example two
Referring to fig. 2, a flowchart of a hot dictionary switching method according to an embodiment of the present invention is shown, which may specifically include:
step 210, adapted to monitor whether the state of each thermal dictionary changes by calling an inotify API, and return a state change message of the thermal dictionary to a thread pool of an application layer at a kernel layer;
in the embodiment of the present invention, a thread pool may be created in advance, and an inotify API is called by a worker thread in the thread pool to monitor whether the state of each thermal dictionary changes at the kernel layer.
Calling the inotify API in real applications may perform the following steps:
substep S211, initializing a file change monitor for each thermal dictionary through an initialization function inotify _ init () in the inotify API, and returning a file descriptor;
substep S212, adding a function inotify _ add _ watch () through a file change monitor in the inotify API, and registering a file change monitor for the file descriptor;
and a substep S213, after the hot dictionary state change event is monitored by the file change monitor, returning a state change message to the thread pool.
Step 220, receiving a state change message of the hot dictionary by a thread pool;
step 230, setting the loading record of the hot dictionary by the target service to be empty by using each working thread in the thread pool according to the state change message, and triggering a loading function for reloading the hot dictionary; (ii) a
And a thread pool manager (ThreadPool) of the thread pool adds a hot update request task to a request queue (RequestQueue) according to the state change message by a request adding method (putRequest), then the working thread extracts the hot update request task from the request queue (RequestQueue) for execution, sets a loading record of the target service to the hot dictionary to be empty, triggers a loading function for reloading the hot dictionary, and obtains and loads the hot dictionary after the state change through the loading function.
The working thread sets the loading record of the hot dictionary of the target service to be null, namely sets the loading record of the file of the hot dictionary to be null in the registration list of the target service. Then it is necessary for the target service to reload the hot dictionary since the load record for the hot dictionary is set to null.
For example, for the aforementioned require function, the target service may determine in the registry [ "_ load" ] table whether an overheat dictionary has been LOADED. If the hot dictionary is already LOADED, it is recorded in the registry [ "_ LOADED" ] table, and then calling the require function at this time will not be loading the hot dictionary because it is already recorded.
In the embodiment of the present invention, the register value of the hot dictionary corresponding to the notification that the state has changed in the registration of the hot dictionary is set to null, which indicates that the hot dictionary has not been LOADED, in the registration of the hot dictionary, and then the require function is called.
And 240, acquiring the hot dictionary after the state change by the working thread through the loading function and loading.
As in the previous example, after the require function is recalled, the library file of the hot dictionary with changed state can be LOADED from the storage location, and the hot dictionary is recorded in the registry [ "_ LOADED" ] table again.
The embodiment of the invention can monitor whether the state of each hot dictionary changes or not, and if the state change of one hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change, thereby solving the problem that the hot dictionary in the latest state can be used only when the service needs to be restarted, and obtaining the hot dictionary used by each service which can be updated without restarting the service, thereby avoiding the suspension of the online service and ensuring that a user can not interrupt the access to the service.
Secondly, the embodiment of the invention realizes the parallel hot updating process through the thread pool, and does not need to independently establish a thread for each hot dictionary to execute hot updating during hot updating, thereby reducing the expenditure.
Moreover, the state change information is actively returned after the state change of the hot dictionary is monitored through the inotify API, a thread is not required to be established for each hot dictionary, the state change of the hot dictionary is not required to be polled by the thread, and the expenditure is reduced.
EXAMPLE III
Referring to fig. 3, a schematic structural diagram of a hot dictionary switching apparatus according to an embodiment of the present invention is shown, which may specifically include:
a monitoring module 310 adapted to monitor whether the status of each hot dictionary changes;
the hot dictionary switching module 320 is adapted to, if the state change of a hot dictionary is monitored, hot update the hot dictionary currently used by each target service to the hot dictionary after the state change.
Preferably, the hot dictionary switching module includes:
and the thread pool monitoring module is suitable for carrying out monitoring and executing multitask parallel mode through the thread pool to thermally update the thermal dictionary currently used by each target service into the thermal dictionary after the state is changed.
Preferably, the monitoring module comprises:
and the interface monitoring module is suitable for monitoring whether the state of each hot dictionary changes or not by calling the inotify API.
Preferably, the interface listening module includes:
the file descriptor acquisition module is suitable for initializing a file change monitor through an initialization function inotify _ init () in the inotify API and returning a file descriptor for each hot dictionary; (same as above)
The file change monitor adding module is suitable for adding a function inotify _ add _ watch () through a file change monitor in an inotify API and registering a file change monitor for the file descriptor; (same as above)
And the return module is suitable for returning the state change message of the hot dictionary after the state change event of the hot dictionary is monitored by the file change monitor.
Preferably, the hot dictionary switching module includes:
a message receiving module adapted to receive a state change message of the thermal dictionary by a thread pool;
and the first switching module is suitable for utilizing each working thread in the thread pool according to the state change message and aiming at the target service needing to use the hot dictionary, and thermally updating the hot dictionary currently used by the target service into the hot dictionary after the state change.
Preferably, the monitoring module comprises:
whether each hot dictionary is updated or not is monitored. The embodiment of the invention can monitor whether the state of each hot dictionary changes or not, and if the state change of one hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change, thereby solving the problem that the hot dictionary in the latest state can be used only when the service needs to be restarted, and obtaining the hot dictionary used by each service which can be updated without restarting the service, thereby avoiding the suspension of the online service and ensuring that a user can not interrupt the access to the service.
Example four
Referring to FIG. 4, a hot dictionary switch is shown according to an embodiment of the present inventionSchematic structure of the deviceSpecifically, the method may include:
the monitoring module 410 specifically includes:
the interface monitoring module 411 is adapted to monitor whether the state of each thermal dictionary changes by calling an inotify API, and return a state change message of the thermal dictionary to the thread pool of the application layer at the kernel layer;
the hot dictionary switching module 420 specifically includes:
a message receiving module 421 adapted to receive a state change message of the thermal dictionary by a thread pool; .
An unloading module 422, adapted to set a loading record of the hot dictionary to be empty by the target service using each work thread in the thread pool according to the state change message, and trigger a loading function for reloading the hot dictionary;
and the reloading module 423 is adapted to obtain the hot dictionary with changed state and load the hot dictionary through the loading function by the working thread.
The embodiment of the invention can monitor whether the state of each hot dictionary changes or not, and if the state change of one hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change, thereby solving the problem that the hot dictionary in the latest state can be used only when the service needs to be restarted, and obtaining the hot dictionary used by each service which can be updated without restarting the service, thereby avoiding the suspension of the online service and ensuring that a user can not interrupt the access to the service.
Secondly, the embodiment of the invention realizes the parallel hot updating process through the thread pool, does not need to independently establish a thread for each hot dictionary to execute hot updating during hot updating, and reduces the expenditure
Moreover, the state change information is actively returned after the state change of the hot dictionary is monitored through the inotify API, a thread is not required to be established for each hot dictionary, the state change of the hot dictionary is not required to be polled by the thread, and the expenditure is reduced.
EXAMPLE five
Referring to fig. 5, which shows a schematic structural diagram of an electronic device according to an embodiment of the present invention, the electronic device 500 may specifically include:
memory 510 and processor 520;
the memory is used for storing executable codes;
the processor is configured to execute the executable code, the executable code performing a method comprising:
monitoring whether the state of each hot dictionary changes;
and if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change in a hot mode.
Of course, the executable code may also perform a method of any of the foregoing steps, and the embodiments of the present invention are not limited thereto.
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 further, may be divided into a plurality of 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 some or all of the functionality of some or all of the components in an electronic device according to embodiments of the present invention. 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.
A1, a hot dictionary switching method, comprising:
monitoring whether the state of each hot dictionary changes;
and if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change in a hot mode.
A2, wherein the step of hot-updating the hot dictionary currently used by each target service to the hot dictionary after the state change according to the method of B1 comprises:
and the hot dictionary currently used by each target service is thermally updated to the hot dictionary after the state is changed in a mode of monitoring and executing multitask parallel through the thread pool.
A3, the method according to a1, wherein the step of monitoring whether the status of each thermal dictionary changes comprises:
and monitoring whether the state of each hot dictionary changes or not by calling the inotify API.
A4, according to the method in A3, the step of monitoring whether the state of each thermal dictionary changes by calling an inotify API includes:
for each hot dictionary, initializing a file change monitor through an initialization function inotify _ init () in the inotify API, and returning a file descriptor;
adding a function inotify _ add _ watch () through a file change monitor in an inotify API, and registering a file change monitor for the file descriptor; and returning a state change message of the hot dictionary after the state change event of the hot dictionary is monitored by the file change monitor.
A5, according to the method in B4, the hot updating the hot dictionary currently used by each target service to the hot dictionary after the status change includes:
receiving, by a thread pool, a state change message of the thermal dictionary;
and according to the state change message, utilizing each working thread in the thread pool, and aiming at the target service needing to use the thermal dictionary, thermally updating the thermal dictionary currently used by the target service to the thermal dictionary after the state change.
A6, the method according to a1, wherein the monitoring whether the state of each thermal dictionary changes includes:
whether each hot dictionary is updated or not is monitored.
A7, the method according to one of a1-a5, wherein the step of hot-updating the currently used hot dictionary to the hot dictionary after the state change comprises:
setting the loading record of the target service to the hot dictionary to be empty, and triggering a loading function for reloading the hot dictionary;
and acquiring the hot dictionary after the state change through the loading function and loading.
The invention also discloses B8, a hot dictionary switching device, comprising:
the monitoring module is suitable for monitoring whether the state of each hot dictionary changes;
and the hot dictionary switching module is suitable for hot updating the hot dictionary currently used by each target service into the hot dictionary after the state change if the state change of the hot dictionary is monitored.
B9, the apparatus of B8, the hot dictionary switching module comprising:
and the thread pool monitoring module is suitable for carrying out monitoring and executing multitask parallel mode through the thread pool to thermally update the thermal dictionary currently used by each target service into the thermal dictionary after the state is changed.
B10, the apparatus according to B8, the monitoring module comprising:
and the interface monitoring module is suitable for monitoring whether the state of each hot dictionary changes or not by calling the inotify API.
B11, the apparatus of B10, the interface listening module comprising:
the file descriptor acquisition module is suitable for initializing a file change monitor through an initialization function inotify _ init () in the inotify API and returning a file descriptor for each hot dictionary; the file change monitor adding module is suitable for adding a function inotify _ add _ watch () through a file change monitor in an inotify API and registering a file change monitor for the file descriptor;
and the return module is suitable for returning the state change message of the hot dictionary after the state change event of the hot dictionary is monitored by the file change monitor.
B12, the apparatus of B11, the hot dictionary switching module comprising:
a message receiving module adapted to receive a state change message of the thermal dictionary by a thread pool;
and the first switching module is suitable for utilizing each working thread in the thread pool according to the state change message and aiming at the target service needing to use the hot dictionary, and thermally updating the hot dictionary currently used by the target service into the hot dictionary after the state change.
B13, the apparatus according to B8, the monitoring module comprising:
whether each hot dictionary is updated or not is monitored.
B14, the apparatus according to one of B8-B12, the hot dictionary switching module comprising:
the unloading module is suitable for setting the loading record of the target service to the hot dictionary to be empty and triggering a loading function for reloading the hot dictionary;
and the reloading module is suitable for acquiring the hot dictionary with the changed state and loading the hot dictionary through the loading function.
The invention also discloses C15, an electronic device, comprising:
a memory and a processor;
the memory is used for storing executable codes;
the processor is configured to execute the executable code, the executable code performing a method comprising:
monitoring whether the state of each hot dictionary changes;
and if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change in a hot mode.

Claims (11)

1. A hot dictionary switching method includes:
monitoring whether the state of each hot dictionary changes;
if the state change of a hot dictionary is monitored, the hot dictionary currently used by each target service is updated to the hot dictionary after the state change;
wherein the step of hot updating the hot dictionary currently used by each target service to the hot dictionary after the state change comprises:
setting the loading record of the target service to the hot dictionary to be empty, and triggering a loading function for reloading the hot dictionary;
acquiring and loading the hot dictionary after the state change through the loading function;
or, the step of hot updating the hot dictionary currently used by each target service to the hot dictionary after the state change includes:
and the hot dictionary currently used by each target service is thermally updated to the hot dictionary after the state is changed in a mode of monitoring and executing multitask parallel through the thread pool.
2. The method of claim 1, wherein the step of monitoring whether the status of each thermal dictionary changes comprises:
and monitoring whether the state of each hot dictionary changes or not by calling the inotify API.
3. The method of claim 2, wherein the step of monitoring whether the status of each thermal dictionary changes by calling an inotify API comprises:
for each hot dictionary, initializing a file change monitor through an initialization function inotify _ init () in the inotify API, and returning a file descriptor;
adding a function inotify _ add _ watch () through a file change monitor in an inotify API, and registering a file change monitor for the file descriptor; and returning a state change message of the hot dictionary after the state change event of the hot dictionary is monitored by the file change monitor.
4. The method of claim 3, wherein the hot updating the hot dictionary currently used by each target service to the hot dictionary after a state change comprises:
receiving, by a thread pool, a state change message of the thermal dictionary;
and according to the state change message, utilizing each working thread in the thread pool, and aiming at the target service needing to use the thermal dictionary, thermally updating the thermal dictionary currently used by the target service to the thermal dictionary after the state change.
5. The method of claim 1, wherein the monitoring whether the status of each thermal dictionary changes comprises:
whether each hot dictionary is updated or not is monitored.
6. A hot dictionary switching apparatus comprising:
the monitoring module is suitable for monitoring whether the state of each hot dictionary changes;
the hot dictionary switching module is suitable for thermally updating a hot dictionary currently used by each target service into the hot dictionary after the state change if the state change of the hot dictionary is monitored;
wherein the hot dictionary switching module comprises:
the unloading module is suitable for setting the loading record of the target service to the hot dictionary to be empty and triggering a loading function for reloading the hot dictionary;
the reloading module is suitable for acquiring the hot dictionary after the state change through the loading function and loading the hot dictionary;
or, the hot dictionary switching module includes:
and the thread pool monitoring module is suitable for carrying out monitoring and executing multitask parallel mode through the thread pool to thermally update the thermal dictionary currently used by each target service into the thermal dictionary after the state is changed.
7. The apparatus of claim 6, wherein the monitoring module comprises:
and the interface monitoring module is suitable for monitoring whether the state of each hot dictionary changes or not by calling the inotify API.
8. The apparatus of claim 7, wherein the interface listening module comprises:
the file descriptor acquisition module is suitable for initializing a file change monitor through an initialization function inotify _ init () in the inotify API and returning a file descriptor for each hot dictionary; the file change monitor adding module is suitable for adding a function inotify _ add _ watch () through a file change monitor in an inotify API and registering a file change monitor for the file descriptor;
and the return module is suitable for returning the state change message of the hot dictionary after the state change event of the hot dictionary is monitored by the file change monitor.
9. The apparatus of claim 8, wherein the thermal dictionary switching module comprises:
a message receiving module adapted to receive a state change message of the thermal dictionary by a thread pool;
and the first switching module is suitable for utilizing each working thread in the thread pool according to the state change message and aiming at the target service needing to use the hot dictionary, and thermally updating the hot dictionary currently used by the target service into the hot dictionary after the state change.
10. The apparatus of claim 6, wherein the monitoring module comprises:
whether each hot dictionary is updated or not is monitored.
11. An electronic device, comprising:
a memory and a processor;
the memory is used for storing executable codes;
the processor is configured to execute the executable code, which performs the hot dictionary switching method according to any one of claims 1 to 5.
CN201510698232.3A 2015-10-23 2015-10-23 Hot dictionary switching method and device Active CN106610996B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510698232.3A CN106610996B (en) 2015-10-23 2015-10-23 Hot dictionary switching method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510698232.3A CN106610996B (en) 2015-10-23 2015-10-23 Hot dictionary switching method and device

Publications (2)

Publication Number Publication Date
CN106610996A CN106610996A (en) 2017-05-03
CN106610996B true CN106610996B (en) 2022-03-11

Family

ID=58612981

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510698232.3A Active CN106610996B (en) 2015-10-23 2015-10-23 Hot dictionary switching method and device

Country Status (1)

Country Link
CN (1) CN106610996B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110019682B (en) * 2017-12-28 2022-12-27 北京京东尚科信息技术有限公司 System, method and apparatus for processing information

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101281543A (en) * 2008-05-13 2008-10-08 华为技术有限公司 File synchronisation method and device
CN102207879A (en) * 2011-06-14 2011-10-05 贵阳朗玛信息技术股份有限公司 Hot-updating method and hot-updating system of Lua script
CN102436373A (en) * 2011-09-13 2012-05-02 上海普元信息技术股份有限公司 Method for realizing resource loading and resource hot-updating in distributed enterprise application system
CN102855249A (en) * 2011-06-30 2013-01-02 中兴通讯股份有限公司 Network element log synchronizing method and network element log synchronizing system
CN104424234A (en) * 2013-08-26 2015-03-18 阿里巴巴集团控股有限公司 Method and device for detecting change of file system and corresponding electronic device
CN104899057A (en) * 2015-05-13 2015-09-09 北京金山安全软件有限公司 Software module updating method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120150881A1 (en) * 2010-12-09 2012-06-14 Seong Hyeon Cho Cloud-hosted multi-media application server

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101281543A (en) * 2008-05-13 2008-10-08 华为技术有限公司 File synchronisation method and device
CN102207879A (en) * 2011-06-14 2011-10-05 贵阳朗玛信息技术股份有限公司 Hot-updating method and hot-updating system of Lua script
CN102855249A (en) * 2011-06-30 2013-01-02 中兴通讯股份有限公司 Network element log synchronizing method and network element log synchronizing system
CN102436373A (en) * 2011-09-13 2012-05-02 上海普元信息技术股份有限公司 Method for realizing resource loading and resource hot-updating in distributed enterprise application system
CN104424234A (en) * 2013-08-26 2015-03-18 阿里巴巴集团控股有限公司 Method and device for detecting change of file system and corresponding electronic device
CN104899057A (en) * 2015-05-13 2015-09-09 北京金山安全软件有限公司 Software module updating method and device

Also Published As

Publication number Publication date
CN106610996A (en) 2017-05-03

Similar Documents

Publication Publication Date Title
CN107729139B (en) Method and device for concurrently acquiring resources
CN111782414B (en) Delay message processing method and system
CN111818117A (en) Data updating method and device, storage medium and electronic equipment
WO2015131542A1 (en) Data processing method, device and system
CN110275768A (en) Data processing method, device and electronic equipment
CN109359092B (en) File management method, desktop display method, device, terminal and medium
US20230153100A1 (en) Method and apparatus for managing model file in inference application
CN115617527A (en) Management method, configuration method, management device and configuration device of thread pool
US20200310828A1 (en) Method, function manager and arrangement for handling function calls
US10936192B2 (en) System and method for event driven storage management
CN111459629A (en) Azkaban-based project operation method and device and terminal equipment
CN113342554B (en) IO multiplexing method, medium, device and operating system
CN107633080B (en) User task processing method and device
CN110286981A (en) The display methods and display system of the use state of virtual cloud desktop server
CN106610996B (en) Hot dictionary switching method and device
CN111881148A (en) Object combination attribute determination method and device and electronic equipment
CN108062224B (en) Data reading and writing method and device based on file handle and computing equipment
CN111399999A (en) Computer resource processing method and device, readable storage medium and computer equipment
US10140155B2 (en) Dynamically provisioning, managing, and executing tasks
CN115421920A (en) Task management method and device for financial product, electronic equipment and storage medium
CN105630889B (en) Universal caching method and device
CN113867838A (en) Application program starting method, electronic equipment and computer storage medium
CN112134953A (en) Self-adaptive response method based on push message, computing device and storage medium
CN107209882B (en) Multi-stage de-registration for managed devices
CN111090515A (en) Access control method, device, terminal equipment and storage medium

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
TR01 Transfer of patent right

Effective date of registration: 20240103

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.