WO2016188293A1 - 数据获取方法和装置 - Google Patents
数据获取方法和装置 Download PDFInfo
- Publication number
- WO2016188293A1 WO2016188293A1 PCT/CN2016/080310 CN2016080310W WO2016188293A1 WO 2016188293 A1 WO2016188293 A1 WO 2016188293A1 CN 2016080310 W CN2016080310 W CN 2016080310W WO 2016188293 A1 WO2016188293 A1 WO 2016188293A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- data
- request
- requests
- transaction
- thread
- 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.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/957—Browsing optimisation, e.g. caching or content distillation
- G06F16/9574—Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
Definitions
- the present invention relates to the field of Internet technologies, and in particular, to a data acquisition method and apparatus.
- modules of the application system have very low coupling between the modules, that is, the modules need to be isolated from each other, and the other modules are not affected by the modification of one module.
- modules need to cooperate with each other. For example, different modules may need the same data, so that different modules may request the same data from the same data source.
- enterprise search front-end applications typically request a back-end data engine through an http service.
- the last content that needs to be displayed to the user includes: keyword related words, navigation data, total keyword result number, search result set, page turning block, wherein the search result set may further include a search searched by keywords.
- search result set may further include a search searched by keywords.
- search by keyword is performed by the first module
- search by keyword related words is performed by the second module
- “formation of page turning blocks” is performed by the third module.
- the first module needs to issue a first data request to the data source based on the keywords entered by the user.
- the second module needs to issue a second data request to the data source according to the keyword related words input by the user.
- the third module needs to determine the total number of search results, and also needs to reissue the first data request and the second data request from the data source. In this way, the amount of requests to the backend data source is increased, and the response time becomes longer.
- a data acquisition method including: creating a transaction for a data acquisition request; determining, within the transaction, a plurality of initial data requests for different data sources, and utilizing each data source for a subsequent data request for response data returned by the plurality of initial data requests; generating the plurality of initial data requests; and according to the plurality of initial data requests,
- the transaction requests data from the corresponding data source in a concurrent manner; receives and caches the response data returned by the data source; and uses the cached response data to provide corresponding response data for subsequent data requests in the transaction.
- a data obtaining apparatus comprising: a creating unit that creates a transaction for a data acquisition request; a determining unit, within the transaction, determining a plurality of initial data requests for different data sources, and a subsequent data request for response data returned by the plurality of initial data requests by each data source; a generating unit that generates the plurality of initial data requests; and a request unit that is within the transaction according to the plurality of initial data requests.
- the present invention Compared with the prior art, the present invention has the following advantages: the embodiment of the present invention creates a transaction for a data acquisition request, and determines an initial data request for the response data that must be separately requested from the data source and cannot depend on other requests within the transaction. And the response data that can rely on the initial data request, the subsequent data request that is not required to be separately requested from the data source, and the parallel data transmission in the transaction for the initial data request, the concurrent cache of these transaction levels, relative to the no transaction level.
- the way of caching, or the way in which all data requests are executed sequentially greatly reduces the data request time and improves the processing speed of the application.
- FIG. 1 is a schematic diagram of an application acquiring data from a data source according to an embodiment of the present invention
- FIG. 2 is a flowchart of a data acquisition method according to an embodiment of the present invention.
- FIG. 3 is a flowchart of a detailed data acquisition method according to an embodiment of the present invention.
- FIG. 4 is a block diagram of a data acquisition apparatus according to another embodiment of the present invention.
- Figure 5 is a block diagram of a determining unit in accordance with one embodiment of the present invention.
- Computer device also referred to as “computer” in the context, is meant an intelligent electronic device that can perform predetermined processing, such as numerical calculations and/or logical calculations, by running a predetermined program or instruction, which can include a processor and The memory is executed by the processor to execute a predetermined process pre-stored in the memory, or is executed by hardware such as an ASIC, an FPGA, and a DSP, or a combination of the two.
- Computer devices include, but are not limited to, servers, personal computers, notebook computers, tablets, smart phones, and the like.
- the computer device includes a user device and a network device.
- the user equipment includes, but is not limited to, a computer, a smart phone, a PDA, etc.
- the network device includes but is not limited to a single network server, a server group composed of multiple network servers, or a cloud computing based computer Or a cloud composed of a network server, wherein cloud computing is a type of distributed computing, a super virtual computer composed of a group of loosely coupled computers.
- the computer device can be operated separately to implement the present invention, and can also access the network and implement the present invention by interacting with other computer devices in the network.
- the network in which the computer device is located includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a VPN network, and the like.
- the user equipment, the network equipment, the network, and the like are merely examples, and other existing or future possible computer equipment or networks, such as those applicable to the present invention, are also included in the scope of the present invention. It is included here by reference.
- an initial data request for requesting data that must be separately requested from a data source and cannot depend on other requests is first determined, that is, a data request of data A is requested from data source A, and data is requested from data source B.
- the initial data request that is, the data request requesting data A from data source A, the data request requesting data B from data source B, and the data request requesting data C from data source C are transmitted in parallel, which greatly reduces the time for data acquisition.
- Embodiment 1 Data acquisition method.
- the method of the embodiment is mainly implemented by a computer device; the computer device herein includes but is not limited to a PC (such as a desktop PC), a mobile terminal, a cloud composed of a plurality of PCs, and the like.
- a PC such as a desktop PC
- a mobile terminal such as a mobile phone
- a cloud composed of a plurality of PCs, and the like.
- FIG. 3 is a flowchart of a data acquisition method according to an embodiment of the present invention.
- the method of this embodiment mainly includes: step S100, step S110, step S120, step S130, step S140, and step S150.
- S100 Create a transaction for a data acquisition request.
- the data acquisition request is, for example, a request by the user to search using a keyword
- the data to be acquired is a page search result including the keyword or related to the keyword.
- a transaction is a program execution unit that accesses and possibly updates various data items in the database. Transactions are usually caused by the execution of user programs written in advanced database manipulation languages or programming languages.
- the embodiment of the present invention first creates a transaction, and then determines the plurality of initial data requests and the subsequent data requests in the transaction and allocates a context cache space for them. After the initial data request is sent to the data source, the response data returned by the data source is cached in the context cache space. In response to the end of the transaction, the response data of the context cache space cache is cleared.
- the advantage of this is that the content in the context cache space is cleared after the transaction ends, thus releasing the context cache space and avoiding the problem of insufficient cache caused by the surge of cache amount.
- the cache level implemented by the transaction level plus the local memory mode can effectively control the size of the cache, and the memory is not over-used, and the high efficiency of the local memory cache also helps to improve the data acquisition speed of the embodiment of the present invention.
- Transactions can be created by methods known in the art. For example, set the transaction ID and bind it to the thread variable (threadlocal) of the thread that handles the data fetch request.
- S110 Within the transaction, determine a plurality of initial data requests for different data sources, and subsequent data requests for response data returned by the respective data sources for the plurality of initial data requests.
- step S110 can be implemented by the following process:
- a thread is an execution program that processes a data acquisition request in an application, obtains corresponding data for the data acquisition request (eg, processes a search request with a keyword, and generates a search result for the thread).
- a data request needs to be issued during its execution.
- the thread can be retrieved from a predetermined thread pool, such as by a maintenance person from among a plurality of predetermined threads in a predetermined thread pool.
- a predetermined thread pool such as by a maintenance person from among a plurality of predetermined threads in a predetermined thread pool.
- FIG. 2 it is analyzed from the program statement of the obtained thread that the thread needs to request data A from data source A first, then request data B from data source B, and then request data C from data source C, and then The second request for data A from data source A, the second request for data B from data source B, and the second request for data C from data source C. That is, the above six data requests need to be executed.
- Embodiments of the present invention also provide a method for helping a user to augment search parameters to automatically determine which data requests need to be sent to which data sources for the data acquisition request. That is, acquiring a search keyword in the data acquisition request, determining a plurality of types of search parameters, determining a plurality of search parameters according to the search keyword and the plurality of search parameter types, thereby determining that each of the plurality of search parameters is Multiple initial data requests to multiple data sources for search parameters.
- determining the search parameter types in advance includes: a keyword search parameter, a keyword related word search parameter, and a keyword promotion type search parameter.
- the search parameters determined are: “laptop” is a keyword search parameter; “laptop” is synonymous or synonym “tablet”, " “notebook computer” is a keyword-related word search parameter; keyword promotion class search parameter, for example, for the keyword "laptop” input by the user, to judge that it is an electronic product enthusiast, and thus the digital phase of the Canon company recently The advertisement of the machine is pushed to the user, so the keyword promotion type search parameter may be "X872 type digital camera".
- search parameters For example, three initial data requests are determined, one of which is a data request from a "laptop" as a search parameter to, for example, data sources A, B, C, and another initial data request is
- the "tablet", "notebook” are used as search parameters to request data from, for example, data sources D, E, and the other initial data request is to request data from, for example, data source F as a search parameter "X872 type digital camera".
- the embodiment of the present invention provides a method for concurrently requesting each back-end data source and buffering the response data of each data source into the context cache space, which is optimized at the time of designing the application system framework (the embodiment of the present invention is based on The thread will automatically determine the initial data request and subsequent data requests), so that application developers can focus on these caches and concurrent logic during development, and achieve efficient and rapid development.
- the plurality of initial data requests may be generated in a manner known in the art, such as an example.
- each initial data request can be automatically monitored, and once the initial data request is in the ready state, a non-blocking mode transmission channel is turned on.
- This reception and caching can be accomplished in a manner known in the art.
- this embodiment may determine that a timeout occurs, The initial data request is sent again to the corresponding data source. If more than two data requests time out, the resending of the initial data request can still be performed in a concurrent form. If the number of timeouts of the initial data request reaches a predetermined number of times, the embodiment may not continue to send the initial data request and return the initial data request timeout information to the service layer.
- Embodiment 2 is a specific data acquisition method. The flow of the method is shown in Figure 3.
- step S200 when receiving the data acquisition request, the present embodiment proceeds to step S200.
- S200 Start processing the data acquisition request, such as selecting a thread from the thread pool, and using the thread to process the data acquisition request.
- S210 Create a transaction for the data acquisition request. For example, setting a transaction identifier for the data acquisition request, and binding the transaction identifier to a thread variable (threadlocal) corresponding to the thread processing the current data acquisition request, so that the thread processing the current data acquisition request explicitly knows that a transaction has been create. Allocating a context cache space for the transaction in the local cache space, and binding the allocated context cache space to the thread variable (threadlocal) corresponding to the thread processing the current data acquisition request, so that the thread processing the current data acquisition request can Get information such as the context of the transaction from its corresponding thread variable (threadlocal).
- a plurality of initial data requests, and subsequent data requests are determined.
- the search parameters determine three initial data requests with keyword search parameters, keyword related word search parameters, and keyword promotion class search parameters, respectively.
- S220 Generate a plurality of initial data requests, for example, three initial data requests respectively having a keyword search parameter, a keyword related word search parameter, and a keyword promotion type search parameter.
- step S240 Determine whether the initial data request for all search parameter types is processed. If there is still an unprocessed search parameter type, then to step S250, if there is no unprocessed search parameter type, then step S260.
- next search parameter type Read a next search parameter type, and generate a data request by using the search parameter type and the search keyword.
- the search parameter type currently transmitting the initial data request is a keyword related word search parameter
- the next search parameter type is a keyword promotion type search parameter. Then, setting the state of the initial data request to the ready state, automatically opening a transmission channel running in the non-blocking mode for the data request of the ready state, and sending the data request in the ready state to the data source through the transmission channel Then, the process returns to step S240.
- step S270 Determine whether there is readable response data on each transmission channel, and determine whether the initial data request times out. If it is determined that there is readable response data and the data request does not time out, then to step S280, if it is determined that there is no readable response data or the data request times out, then step S290.
- step S280 Receive and parse the response data, and buffer the response data received and parsed, and return to step S270.
- S291 The business processing logic in the business layer separately parses all the cached response data into a plurality of business objects according to actual business requirements, and stores the parsed plurality of business objects in the context cache space.
- step S292. Determine whether a subsequent data request is received. If yes, go to step S293, otherwise go to step S294.
- Embodiment 3 Data acquisition device.
- a data obtaining apparatus 3 includes: a creating unit 300 that creates a transaction for a data acquisition request; and a determining unit 310, within the transaction, determining a plurality of initial data requests for different data sources, and utilizing Each data source is for a subsequent data request of the response data returned by the plurality of initial data requests; the generating unit 320 generates the plurality of initial data requests; and the requesting unit 330, according to the plurality of initial data requests, in the transaction Inwardly in the form of concurrent
- the data source request data is received; the receiving buffer unit 340 receives and buffers the response data returned by the data source; and the providing unit 350 provides the corresponding response data for the subsequent data request in the transaction by using the buffered response data.
- the receive buffer unit 340 caches the response data returned by the data source in a context cache space allocated locally for the transaction, and in response to the end of the transaction, clears the response data cached in the context cache space.
- the determining unit 310 includes: a first acquiring subunit 3100, acquiring a thread that processes the received data obtaining request; and a second obtaining subunit 3101, which needs to be executed in the thread obtained from the obtained thread.
- the data request determining unit 3102 determines an initial data request and a subsequent data request according to the data source for the data request to be executed in the acquired thread.
- the thread that processes the received data acquisition request is obtained from a predetermined thread pool.
- the second obtaining subunit acquires the search keywords in the data obtaining request, and determines multiple search parameter types, according to the search key.
- the word and the plurality of search parameter types determine a plurality of search parameters to determine a plurality of initial data requests to the plurality of data sources with the plurality of search parameters, respectively.
- the present invention can be implemented in software and/or a combination of software and hardware.
- the various devices of the present invention can be implemented using an application specific integrated circuit (ASIC) or any other similar hardware device.
- the software program of the present invention may be executed by a processor to implement the steps or functions described above.
- the software program (including related data structures) of the present invention can be stored in a computer readable recording medium such as a RAM memory, a magnetic or optical drive or a floppy disk and the like.
- some of the steps or functions of the present invention may be implemented in hardware, for example, as a circuit that cooperates with a processor to perform various steps or functions.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Memory System Of A Hierarchy Structure (AREA)
Abstract
本发明提供了一种数据获取方法和装置。该数据获取方法包括:针对数据获取请求,创建事务;在所述事务内,确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求;生成所述多个初始数据请求;根据所述多个初始数据请求,在所述事务内以并发的形式分别向相应的数据源请求数据;接收并缓存所述数据源返回的响应数据;利用缓存的响应数据为所述事务内的后续数据请求提供相应的响应数据。本发明提高了应用获取数据的获取速度。
Description
本发明涉及互联网技术领域,尤其涉及一种数据获取方法和装置。
在互联网技术领域中,众多应用系统都会涉及到从数据源处获取相应的数据的过程,而且往往需要多次向数据源获取数据。对于模块化比较高的应用系统,要求应用系统的各个模块之间具有非常低的耦合性,即模块之间需要相互隔离,不会因为一个模块的改动对其他的模块产生影响。而在某些应用场景下,模块之间又是需要相互协作,例如不同模块可能会需要相同的数据,造成不同模块可能向相同数据源请求相同数据。
例如,企业级搜索前端应用一般都是通过http服务请求后端数据引擎。对于一次请求,最后向用户需要展示的内容包括:关键词相关词,导航数据,关键词总结果数,搜索结果集,翻页区块,其中搜索结果集可以又包括用关键词搜索出来的搜索结果子集、和用关键词相关词搜索出来的搜索结果子集。在模块化设计中,可能“用关键词搜索”是第一模块执行的,“用关键词相关词搜索”是第二模块执行的,“形成翻页区块”是第三模块执行的。第一模块需要根据用户输入的关键词向数据源发出第一数据请求。第二模块需要根据用户输入的关键词相关词向数据源发出第二数据请求。第三模块为了确定总页数,需要确定搜索结果总数,同样需要将数据源重新发出第一数据请求和第二数据请求。这样,加大了对后端数据源的请求量,响应时间变长。
发明内容
本发明的一个目的是减小应用获取数据的获取时间。
根据本发明的一个方面,提供了一种数据获取方法,包括:针对数据获取请求,创建事务;在所述事务内,确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求;生成所述多个初始数据请求;根据所述多个初始数据请求,在所述
事务内以并发的形式分别向相应的数据源请求数据;接收并缓存所述数据源返回的响应数据;利用缓存的响应数据为所述所述事务内的后续数据请求提供相应的响应数据。
根据本发明的一个方面,提供了一种数据获取装置,包括:创建单元,针对数据获取请求,创建事务;确定单元,在所述事务内,确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求;生成单元,生成所述多个初始数据请求;请求单元,根据所述多个初始数据请求,在所述事务内以并发的形式分别向相应的数据源请求数据;接收缓存单元,接收并缓存所述数据源返回的响应数据;提供单元,利用缓存的响应数据为所述事务内的后续数据请求提供相应的响应数据。
与现有技术相比,本发明具有以下优点:本发明实施例针对一个数据获取请求创建一个事务,并在事务内确定出必须单独向数据源请求、不能依赖其它请求的响应数据的初始数据请求、以及可以依赖于初始数据请求的响应数据、不用再单独向数据源请求的后续数据请求,对于初始数据请求在事务内采用并行方式发送,这些事务级的并发缓存的方式,相对于无事务级缓存的方式,或是所有数据请求顺序执行的方式,大大减少了数据请求时间,提高了应用的处理速度。
通过阅读参照以下附图所作的对非限制性实施例所作的详细描述,本发明的其它特征、目的和优点将会变得更明显:
图1为本发明一个实施例中应用向数据源获取数据的示意图;
图2为本发明一个实施例的数据获取方法的流程图;
图3为本发明一个实施例的详细数据获取方法的流程图;
图4为本发明另一个实施例的数据获取装置的框图。
图5为根据本发明一个实施例的确定单元的框图。
在更加详细地讨论示例性实施例之前应当提到的是,一些示例性实施例被描述成作为流程图描绘的处理或方法。虽然流程图将各项操作描述成顺序的处理,但是,其中的许多操作是可以被并行地、并发地或者同时实施。此外,各项操作的顺序可以被重新安排。当其操作完成时,所述处理可以被终止,但是,还可以具有未包括在附图中的附加步骤。所述处理可以对应于方法、函数、规程、子例程、子程序等等。
在上下文中所称“计算机设备”,也称为“电脑”,是指可以通过运行预定程序或指令来执行数值计算和/或逻辑计算等预定处理过程的智能电子设备,其可以包括处理器与存储器,由处理器执行在存储器中预存的存续指令来执行预定处理过程,或者是由ASIC、FPGA以及DSP等硬件执行预定处理过程,或是由上述二者组合来实现。计算机设备包括但不限于服务器、个人电脑、笔记本电脑、平板电脑、智能手机等。
所述计算机设备包括用户设备与网络设备。其中,所述用户设备包括但不限于电脑、智能手机、PDA等;所述网络设备包括但不限于单个网络服务器、多个网络服务器组成的服务器组或基于云计算(Cloud Computing)的由大量计算机或网络服务器构成的云,其中,云计算是分布式计算的一种,由一群松散耦合的计算机集组成的一个超级虚拟计算机。其中,所述计算机设备可单独运行来实现本发明,也可接入网络并通过与网络中的其他计算机设备的交互操作来实现本发明。其中,所述计算机设备所处的网络包括但不限于互联网、广域网、城域网、局域网、VPN网络等。
需要说明的是,所述用户设备、网络设备和网络等仅为举例,其他现有的或今后可能出现的计算机设备或网络如可适用于本发明,也应包含在本发明保护范围以内,并以引用方式包含于此。
后面讨论的方法(其中一些通过流程图示出)可以通过硬件、软件、固件、中间件、微代码、硬件描述语言或者其任意组合来实施。当用软件、固件、中间件或微代码来实施时,用以实施必要任务的程序代码或代码段可以被存储在机器或计算机可读介质(比如存储介质)中。(一个或多个)处理器可以实施必要的任务。
这里所公开的具体结构和功能细节仅仅是代表性的,并且是用于描述本
发明的示例性实施例的目的。但是本发明可以通过许多替换形式来具体实现,并且不应当被解释成仅仅受限于这里所阐述的实施例。
应当理解的是,虽然在这里可能使用了术语“第一”、“第二”等等来描述各个单元,但是这些单元不应当受这些术语限制。使用这些术语仅仅是为了将一个单元与另一个单元进行区分。举例来说,在不背离示例性实施例的范围的情况下,第一单元可以被称为第二单元,并且类似地第二单元可以被称为第一单元。这里所使用的术语“和/或”包括其中一个或更多所列出的相关联项目的任意和所有组合。
这里所使用的术语仅仅是为了描述具体实施例而不意图限制示例性实施例。除非上下文明确地另有所指,否则这里所使用的单数形式“一个”、“一项”还意图包括复数。还应当理解的是,这里所使用的术语“包括”和/或“包含”规定所陈述的特征、整数、步骤、操作、单元和/或组件的存在,而不排除存在或添加一个或更多其他特征、整数、步骤、操作、单元、组件和/或其组合。
还应当提到的是,在一些替换实现方式中,所提到的功能/动作可以按照不同于附图中标示的顺序发生。举例来说,取决于所涉及的功能/动作,相继示出的两幅图实际上可以基本上同时执行或者有时可以按照相反的顺序来执行。
下面结合附图对本发明提供的技术方案作进一步详细描述。
现参照本发明实施例的图1,对本发明实施例的主要原理进行简要说明。
在本发明实施例的图1中,先确定出必须单独向数据源请求、不能依赖其它请求的响应数据的初始数据请求,即向数据源A请求数据A的数据请求、向数据源B请求数据B的数据请求、向数据源C请求数据C的数据请求,以及后续依赖于初始数据请求的响应数据、不用再单独向数据源请求的后续数据请求,即再次请求数据A的请求、再次请求数据B的请求、再次请求数据C的请求。将初始数据请求,即向数据源A请求数据A的数据请求、向数据源B请求数据B的数据请求、向数据源C请求数据C的数据请求,并行发送,大大减少了数据获取的时间。当数据A-C分别从数据源A-C获取到后,再次请求数据A的请求、再次请求数据B的请求、再次请求数据C的请求就可以直接利用本地缓存中缓存的数据A-C,不用再次向数据源A-C请求数据。
下面基于上述实现原理并结合附图2-5对本发明提供的数据获取方法和数据获取装置的实施例分别进行说明。
实施例一、数据获取方法。
其中,本实施例的方法主要通过计算机设备来实现;这里的计算机设备包括但不限于PC机(如台式PC机)以及移动终端、由若干PC机组成的云等。
图3为本实施例的数据获取方法流程图。
图3中,本实施例的方法主要包括:步骤S100、步骤S110、步骤S120、步骤S130、步骤S140、步骤S150。
S100、针对数据获取请求,创建事务。
数据获取请求例如用户利用关键词进行搜索的请求,其要获取的数据是包含该关键词或与该关键词相关的页面搜索结果。
事务是访问并可能更新数据库中各种数据项的一个程序执行单元。事务通常由高级数据库操纵语言或编程语言书写的用户程序的执行所引起。本发明实施例首先创建事务,然后在事务中确定所述多个初始数据请求、以及所述后续数据请求,并为其在分配上下文缓存空间。下文中向数据源发出初始数据请求后,数据源返回的响应数据就缓存于该上下文缓存空间内。响应于事务结束,清除该上下文缓存空间缓存的响应数据。这样做的好处是,在事务结束后清除上下文缓存空间中的内容,从而释放上下文缓存空间,避免缓存量激增造成的缓存不足的问题。因为是事务级别的缓存,而非整个应用系统层次,所以不同事务中的请求之间也能做到相互隔离不受影响。事务级别加本地内存方式实现的缓存能够有效地控制缓存的规模,不至于导致内存过度使用,且本地内存缓存效率高的特点也有助于提高本发明实施例的数据获取速度。
事务可以通过本领域已知的方法创建。例如,设置事务标识,并将其与处理数据获取请求的线程的线程变量(threadlocal)绑定。
S110、在所述事务内,确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求。
在一种实施方式中,步骤S110可以通过以下过程实现:
-获取处理接收到的数据获取请求的线程。
线程是应用中处理数据获取请求、为该数据获取请求获取相应的数据(例如处理带有关键词的搜索请求,为其产生搜索结果)的执行程序。其执行过程中需要发出数据请求。
该线程可以从预定线程池中获取,例如由维护人员从预定线程池中的多个预定线程中指定。这样做的优点是,由于预定线程池中的线程的数量是预先设定的,因此,线程池中的线程的数量会限制同时开启的事务总数,从而避免了开启过多事务、占用过多缓存的问题。由于现有技术线程池中线程产生的数据不会自动清除,会占用内存空间。本发明实施例中在事务结束后清除相应上下文内存空间的做法,会有助于消除内存膨胀引起的缓存不足。
-从获取的线程中获取线程中需要执行的数据请求。
以图2为例,从获取的线程的程序语句中分析出该线程需要先请求来自数据源A的数据A,再请求来自数据源B的数据B,再请求来自数据源C的数据C,然后第二次请求来自数据源A的数据A,第二次请求来自数据源B的数据B,第二次请求来自数据源C的数据C。即,需要执行以上6个数据请求。
上例中,在线程中对需要哪个数据源的哪个数据,规定得非常清楚。但对于一些线程,可能只规定需要根据数据获取请求中的关键词向多个数据源搜索。本发明实施例还提供了一种帮助用户扩充搜索参数,从而为该数据获取请求自动确定需要向哪些数据源发出哪些初始数据请求。即,获取所述数据获取请求中的搜索关键词,确定多种搜索参数类型,根据搜索关键词和所述多种搜索参数类型,确定多种搜索参数,从而确定出分别带有所述多种搜索参数的、向多个数据源的多个初始数据请求。
举例来说,事先确定搜索参数类型包括:关键词搜索参数、关键词相关词搜索参数以及关键词推广类搜索参数。这时,根据搜索关键词“笔记本电脑”和这三种搜索参数类型,确定出的搜索参数为:“笔记本电脑”是关键词搜索参数;“笔记本电脑”的同义词或近义词“平板电脑”、“笔记本计算机”等是关键词相关词搜索参数;关键词推广类搜索参数例如,针对用户输入的关键词“笔记本电脑”,判断其是一个电子产品爱好者,因而将佳能公司最近出的数码相
机的广告推送给用户,因而关键词推广类搜索参数可能是“X872型数码相机”。当这些搜索参数确定后,就例如确定出三个初始数据请求,其中一个初始数据请求是以“笔记本电脑”作为搜索参数向例如数据源A、B、C的数据请求,另一个初始数据请求是以“平板电脑”、“笔记本计算机”作为搜索参数向例如数据源D、E的数据请求,另一个初始数据请求是以“X872型数码相机”作为搜索参数向例如数据源F的数据请求。
-根据获取的线程中需要执行的数据请求针对的数据源,确定初始数据请求和后续数据请求。
以图2为例,由于以上6个数据请求中,前三个数据请求的数据源分别是A、B、C,后三个数据请求的数据源也分别是A、B、C,因此将前三个数据请求确定为初始数据请求,后三个数据请求确定为后续数据请求。
本发明实施例提出了一种并发请求各后端数据源,并将各数据源的响应数据缓存到上下文缓存空间中的方法,是在应用系统框架的设计的时候进行优化(本发明实施例根据线程会自动确定初始数据请求和后续数据请求),使得应用开发者在开发的时候可以不用关注这些缓存以及并发的逻辑,做到高效快捷的开发。
S120、生成所述多个初始数据请求。
可以以本领域已知的方式,例如实例的方式,生成所述多个初始数据请求。
S130、根据所述多个初始数据请求,在所述事务内以并发的形式分别向相应的数据源请求数据。
可以通过本领域已知的多种方式实现这种并发请求。
例如,可以通过自动监视各初始数据请求的状态,一旦该初始数据请求处于就绪状态,就为其开启一个非阻塞模式的传输通道。
S140、接收并缓存所述数据源返回的响应数据。
可以通过本领域已知的方式实现这种接收和缓存。
本实施例如果在发出初始数据请求后预定时间间隔内,没有接收到某个或者某些或者所有数据源返回的响应数据,则判断产生了数据请求超时现象。在判断产生了数据请求超时现象的情况下,本实施例可以在判断出超时后,
再次向相应的数据源发送初始数据请求。如果有两个以上数据请求发生超时,仍可以采用并发的形式进行初始数据请求的再次发送操作。如果初始数据请求的超时次数达到了预定次数,本实施例可以不再继续发送初始数据请求,并向业务层返回初始数据请求超时信息。
S150、利用缓存的响应数据为所述事务内的后续数据请求提供相应的响应数据。
如图2所示,当数据A-C分别从数据源A-C获取到并缓存在本地后,再次请求数据A的请求、再次请求数据B的请求、再次请求数据C的请求就可以直接利用本地缓存中缓存的数据A-C,不用再次向数据源A-C请求数据。
实施例二、一种具体的数据获取方法。该方法的流程如图3所示。
图4中,本实施例在接收到数据获取请求时,到步骤S200。
S200、开始对数据获取请求的处理,如从线程池中选择一线程,并利用该线程对数据获取请求进行处理。
S210、针对该数据获取请求创建一事务。例如,为该数据获取请求设置一个事务标识,并将该事务标识与处理当前数据获取请求的线程所对应的线程变量(threadlocal)绑定,以使处理当前数据获取请求的线程明确获知一个事务已经创建。在本地缓存空间中为该事务分配一个上下文缓存空间,并将分配的该上下文缓存空间与处理当前数据获取请求的线程对应的线程变量(threadlocal)绑定,以使处理当前数据获取请求的线程可以从其对应的线程变量(threadlocal)处获取事务的上下文等信息。在所述事务中,确定多个初始数据请求、以及后续数据请求。在确定多个初始数据请求时,获取数据获取请求中的搜索关键词,根据搜索关键词和预先确定的多种搜索参数类型,确定关键词搜索参数、关键词相关词搜索参数以及关键词推广类搜索参数,确定出分别带有关键词搜索参数、关键词相关词搜索参数以及关键词推广类搜索参数的三个初始数据请求。
S220、生成多个初始数据请求,例如分别带有关键词搜索参数、关键词相关词搜索参数以及关键词推广类搜索参数的三个初始数据请求。
S230、开始初始数据请求的并发发送。
S240、判断是否针对所有的搜索参数类型的初始数据请求都处理完成。
如果还有未处理的搜索参数类型,则到步骤S250,如果不存在未处理的搜索参数类型,则到步骤S260。
S250、读取下一个搜索参数类型,并利用该搜索参数类型和搜索关键词生成数据请求。例如,当前发送初始数据请求的搜索参数类型是关键词相关词搜索参数,则下一个搜索参数类型就是关键词推广类搜索参数。然后,将该初始数据请求的状态设置为就绪状态,自动针对该就绪状态的数据请求开启一条运行于非阻塞模式的传输通道,并使该处于就绪状态的数据请求通过该传输通道向数据源发送;之后返回步骤S240。
S260、开始对数据源返回的响应数据进行处理。
S270、判断各传输通道上是否有可读的响应数据,并判断初始数据请求是否超时。如果确定有可读的响应数据且数据请求没有超时,则到步骤S280,如果确定没有可读的响应数据或数据请求超时,则到步骤S290。
S280、接收并解析响应数据,并将接收解析的响应数据缓存起来,返回步骤S270。
S290、初始数据请求的并发处理结束。
S291、业务层中的业务处理逻辑根据实际的业务需求将上述缓存的所有响应数据分别解析成多个业务对象,并将解析后的多个业务对象分别存储于上下文缓存空间。
S292、判断是否接收到后续数据请求。如果接收到,则到步骤S293,否则到步骤S294。
S293、直接从上下文缓存空间中获取对应的响应数据,并返回步骤S292。
S294、结束事务,并释放事务的上下文所占据的上下文缓存空间。
S295、本次数据获取请求处理结束。
实施例三、数据获取装置。
如图4所示,一种数据获取装置3包括:创建单元300,针对数据获取请求,创建事务;确定单元310,在所述事务内,确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求;生成单元320,生成所述多个初始数据请求;请求单元330,根据所述多个初始数据请求,在所述事务内以并发的形式分别向相
应的数据源请求数据;接收缓存单元340,接收并缓存所述数据源返回的响应数据;提供单元350,利用缓存的响应数据为所述事务内的后续数据请求提供相应的响应数据。
可选地,接收缓存单元340将所述数据源返回的响应数据缓存于为所述事务在本地分配的上下文缓存空间中,且响应于事务结束,清除该上下文缓存空间中缓存的响应数据。
可选地,如图5所示,确定单元310包括:第一获取子单元3100,获取处理接收到的数据获取请求的线程;第二获取子单元3101,从获取的线程中获取线程中需要执行的数据请求;确定子单元3102,根据获取的线程中需要执行的数据请求针对的数据源,确定初始数据请求和后续数据请求。
可选地,所述处理接收到的数据获取请求的线程是从预定线程池中获取的。
可选地,如果线程中需要根据数据获取请求中的关键词向多个数据源搜索,第二获取子单元获取所述数据获取请求中的搜索关键词,确定多种搜索参数类型,根据搜索关键词和所述多种搜索参数类型确定多种搜索参数,从而确定出分别带有所述多种搜索参数的、向多个数据源的多个初始数据请求。
需要注意的是,本发明可在软件和/或软件与硬件的组合体中被实施,例如,本发明的各个装置可采用专用集成电路(ASIC)或任何其他类似硬件设备来实现。在一个实施例中,本发明的软件程序可以通过处理器执行以实现上文所述步骤或功能。同样地,本发明的软件程序(包括相关的数据结构)可以被存储到计算机可读记录介质中,例如,RAM存储器,磁或光驱动器或软磁盘及类似设备。另外,本发明的一些步骤或功能可采用硬件来实现,例如,作为与处理器配合从而执行各个步骤或功能的电路。
对于本领域技术人员而言,显然本发明并不限于上述示范性实施例的细节,而且在不背离本发明的精神或基本特征的情况下,能够以其他的具体形式实现本发明。因此,无论从哪一点来看,均应该将上述实施例看作是示范性的,而且是非限制性的,本发明的范围由所附权利要求限定,而不是由上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化涵括在本发明内。不应该将权利要求中的任何附图标记视为限制所涉及的
权利要求。此外,显然“包括”一词不排除其他单元或步骤,单数不排除复数。系统权利要求中陈述的多个单元或装置也可以由一个单元或装置通过软件或者硬件来实现。第一,第二等词语用来表示名称,而并不表示任何特定的顺序。
虽然前面特别示出并且描述了示例性实施例,但是本领域技术人员将会理解的是,在不背离权利要求书的精神和范围的情况下,在其形式和细节方面可以有所变化。这里所寻求的保护在所附权利要求书中做了阐述。
Claims (10)
- 一种数据获取方法,包括:针对数据获取请求,创建事务;在所述事务内,确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求;生成所述多个初始数据请求;根据所述多个初始数据请求,在所述事务内以并发的形式分别向相应的数据源请求数据;接收并缓存所述数据源返回的响应数据;利用缓存的响应数据为所述事务内的后续数据请求提供相应的响应数据。
- 根据权利要求1所述的数据获取方法,其中将所述数据源返回的响应数据缓存于为所述事务在本地分配的上下文缓存空间中,且响应于事务结束,清除该上下文缓存空间中缓存的响应数据。
- 根据权利要求2所述的数据获取方法,其中所述确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求的步骤包括:获取处理接收到的数据获取请求的线程;从获取的线程中获取线程中需要执行的数据请求;根据获取的线程中需要执行的数据请求针对的数据源,确定初始数据请求和后续数据请求。
- 根据权利要求3所述的数据获取方法,其中所述处理接收到的数据获取请求的线程是从预定线程池中获取的。
- 根据权利要求3所述的数据获取方法,其中所述从获取的线程中获取线程中需要执行的数据请求的步骤包括:如果线程中需要根据数据获取请求中的关键词向多个数据源搜索,获取所述数据获取请求中的搜索关键词,确定多种搜索参数类型,根据搜索关键词和所述多种搜索参数类型确定多种搜索参数,从而确定出分别带有所述多 种搜索参数的、向多个数据源的多个初始数据请求。
- 一种数据获取装置,包括:创建单元,针对数据获取请求,创建事务;确定单元,在所述事务内,确定针对不同数据源的多个初始数据请求、以及利用各数据源针对所述多个初始数据请求返回的响应数据的后续数据请求;生成单元,生成所述多个初始数据请求;请求单元,根据所述多个初始数据请求,在所述事务内以并发的形式分别向相应的数据源请求数据;接收缓存单元,接收并缓存所述数据源返回的响应数据;提供单元,利用缓存的响应数据为所述事务内的后续数据请求提供相应的响应数据。
- 根据权利要求6所述的数据获取装置,其中接收缓存单元将所述数据源返回的响应数据缓存于为所述事务在本地分配的上下文缓存空间中,且响应于事务结束,清除该上下文缓存空间中缓存的响应数据。
- 根据权利要求7所述的数据获取装置,其中确定单元包括:第一获取子单元,获取处理接收到的数据获取请求的线程;第二获取子单元,从获取的线程中获取线程中需要执行的数据请求;确定子单元,根据获取的线程中需要执行的数据请求针对的数据源,确定初始数据请求和后续数据请求。
- 根据权利要求8所述的数据获取装置,其中所述处理接收到的数据获取请求的线程是从预定线程池中获取的。
- 根据权利要求8所述的数据获取装置,其中如果线程中需要根据数据获取请求中的关键词向多个数据源搜索,第二获取子单元获取所述数据获取请求中的搜索关键词,确定多种搜索参数类型,根据搜索关键词和所述多种搜索参数类型确定多种搜索参数,从而确定出分别带有所述多种搜索参数的、向多个数据源的多个初始数据请求。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201510284862.6 | 2015-05-28 | ||
| CN201510284862.6A CN106294452B (zh) | 2015-05-28 | 2015-05-28 | 数据获取方法和装置 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2016188293A1 true WO2016188293A1 (zh) | 2016-12-01 |
Family
ID=57392584
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2016/080310 Ceased WO2016188293A1 (zh) | 2015-05-28 | 2016-04-27 | 数据获取方法和装置 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN106294452B (zh) |
| WO (1) | WO2016188293A1 (zh) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113448999A (zh) * | 2021-06-29 | 2021-09-28 | 未鲲(上海)科技服务有限公司 | 数据获取方法、装置、设备及可读存储介质 |
| CN113806813A (zh) * | 2021-08-27 | 2021-12-17 | 上海得帆信息技术有限公司 | 一种多数据源的数据隔离切换方法和系统 |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1908915A (zh) * | 2005-08-02 | 2007-02-07 | 国际商业机器公司 | 用于管理元数据的方法和系统 |
| CN103731427A (zh) * | 2013-12-31 | 2014-04-16 | 华为技术有限公司 | 一种会话处理的方法、设备和系统 |
| US20140136680A1 (en) * | 2012-11-09 | 2014-05-15 | Citrix Systems, Inc. | Systems and methods for appflow for datastream |
| CN104539715A (zh) * | 2014-12-31 | 2015-04-22 | 中山大学 | 一种网络多内容请求响应方法 |
Family Cites Families (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| KR101657196B1 (ko) * | 2009-12-01 | 2016-09-19 | 밴트릭스 코오퍼레이션 | 캐시를 이용한 효율적인 미디어 배송 시스템 및 방법 |
| CN102917021A (zh) * | 2012-09-19 | 2013-02-06 | 深圳市融创天下科技股份有限公司 | 一种基于Web服务的数据返回方法、系统和终端设备 |
| CN104111957B (zh) * | 2013-04-22 | 2017-08-11 | 阿里巴巴集团控股有限公司 | 一种分布式事务同步的方法及系统 |
-
2015
- 2015-05-28 CN CN201510284862.6A patent/CN106294452B/zh active Active
-
2016
- 2016-04-27 WO PCT/CN2016/080310 patent/WO2016188293A1/zh not_active Ceased
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1908915A (zh) * | 2005-08-02 | 2007-02-07 | 国际商业机器公司 | 用于管理元数据的方法和系统 |
| US20140136680A1 (en) * | 2012-11-09 | 2014-05-15 | Citrix Systems, Inc. | Systems and methods for appflow for datastream |
| CN103731427A (zh) * | 2013-12-31 | 2014-04-16 | 华为技术有限公司 | 一种会话处理的方法、设备和系统 |
| CN104539715A (zh) * | 2014-12-31 | 2015-04-22 | 中山大学 | 一种网络多内容请求响应方法 |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113448999A (zh) * | 2021-06-29 | 2021-09-28 | 未鲲(上海)科技服务有限公司 | 数据获取方法、装置、设备及可读存储介质 |
| CN113806813A (zh) * | 2021-08-27 | 2021-12-17 | 上海得帆信息技术有限公司 | 一种多数据源的数据隔离切换方法和系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN106294452B (zh) | 2019-07-23 |
| CN106294452A (zh) | 2017-01-04 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US8108403B2 (en) | User engagement during large file uploads | |
| US11768907B2 (en) | Search method, search device, electronic device and storage medium | |
| TWI659305B (zh) | 用於擴展私用快取中快取行之獨佔持有之設備 | |
| US9712612B2 (en) | Method for improving mobile network performance via ad-hoc peer-to-peer request partitioning | |
| US9674293B2 (en) | Systems and methods for remote access to IMS databases | |
| CN115203210B (zh) | 哈希表处理方法、装置、设备及计算机可读存储介质 | |
| US20130074095A1 (en) | Handling and reporting of object state transitions on a multiprocess architecture | |
| EP3816821A2 (en) | Search method and apparatus, electronic device and storage medium | |
| US20140089260A1 (en) | Workload transitioning in an in-memory data grid | |
| US9626296B2 (en) | Prefetch list management in a computer system | |
| CN114489622A (zh) | 静态资源管理方法、Node.js应用、电子设备和存储介质 | |
| WO2016188293A1 (zh) | 数据获取方法和装置 | |
| CN109656939B (zh) | 一种缓存更新方法、装置、设备和存储介质 | |
| US20180165018A1 (en) | Partial storage of large files in distinct storage systems | |
| US11381630B2 (en) | Transmitting data over a network in representational state transfer (REST) applications | |
| US9805440B2 (en) | Method and apparatus to improve performance of chained tasks on a graphics processing unit | |
| US10572387B2 (en) | Hardware control of CPU hold of a cache line in private cache where cache invalidate bit is reset upon expiration of timer | |
| CN112948130A (zh) | 一种请求处理方法、装置、电子设备及介质 | |
| WO2025130918A1 (zh) | 一种业务处理装置、方法、设备及存储介质 | |
| JP2026511461A (ja) | 強化されたキャッシュ利用 | |
| CN119988250A (zh) | 缓存管理方法、装置、设备、系统、存储介质及程序产品 | |
| CN116910082A (zh) | Sql语句处理方法、装置、服务器及介质 | |
| CN120315816A (zh) | 批量处理多个用户请求的方法、设备、计算机程序产品 | |
| CN121743277A (zh) | 数据写入方法、装置、设备和存储介质 | |
| CN121326934A (zh) | 数据管理方法、装置、电子设备及存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 16799182 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 16799182 Country of ref document: EP Kind code of ref document: A1 |