CN104408110B - The method, apparatus and system of request of data - Google Patents
The method, apparatus and system of request of data Download PDFInfo
- Publication number
- CN104408110B CN104408110B CN201410681632.9A CN201410681632A CN104408110B CN 104408110 B CN104408110 B CN 104408110B CN 201410681632 A CN201410681632 A CN 201410681632A CN 104408110 B CN104408110 B CN 104408110B
- Authority
- CN
- China
- Prior art keywords
- database
- query request
- coroutine
- console
- query
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 58
- 238000001514 detection method Methods 0.000 claims abstract description 109
- 238000012545 processing Methods 0.000 claims description 46
- 230000004044 response Effects 0.000 claims description 32
- 206010033799 Paralysis Diseases 0.000 abstract description 13
- 238000012360 testing method Methods 0.000 abstract description 13
- 230000008569 process Effects 0.000 description 14
- 230000006870 function Effects 0.000 description 6
- 238000010586 diagram Methods 0.000 description 5
- 230000008901 benefit Effects 0.000 description 4
- 238000013461 design Methods 0.000 description 3
- 230000005540 biological transmission Effects 0.000 description 2
- 238000004590 computer program Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000007726 management method Methods 0.000 description 2
- 239000002699 waste material Substances 0.000 description 2
- 238000000429 assembly Methods 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000010924 continuous production Methods 0.000 description 1
- 230000001788 irregular Effects 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000002156 mixing Methods 0.000 description 1
- 238000012544 monitoring process Methods 0.000 description 1
- 230000000737 periodic effect Effects 0.000 description 1
- 238000003672 processing method Methods 0.000 description 1
- 230000000246 remedial effect Effects 0.000 description 1
- 238000013468 resource allocation Methods 0.000 description 1
- 229920006395 saturated elastomer Polymers 0.000 description 1
- 230000035945 sensitivity Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR 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/951—Indexing; Web crawling techniques
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种数据请求的方法、装置及系统,涉及互联网技术领域,为解决数据库因查询请求过多而发生瘫痪的问题而发明。本发明的方法包括:建立对应数据库的第一协程,并通过第一协程对数据库的负荷状态进行检测,获得检测结果;在接收到终端上报的查询请求时,建立对应查询请求的第二协程,并通过第二协程向第一协程获取检测结果;若检测结果表征数据库处于超负荷状态,则停止向数据库转发查询请求。本发明主要应用于postgresql数据库系统中。
The invention discloses a data request method, device and system, relates to the technical field of the Internet, and is invented for solving the problem that a database is paralyzed due to too many query requests. The method of the present invention includes: establishing the first coroutine corresponding to the database, and detecting the load status of the database through the first coroutine to obtain the detection result; when receiving the query request reported by the terminal, establishing the second coroutine corresponding to the query request Coroutine, and obtain the test result from the first coroutine through the second coroutine; if the test result indicates that the database is in an overloaded state, stop forwarding the query request to the database. The invention is mainly applied in the postgresql database system.
Description
技术领域technical field
本发明涉及互联网技术领域,尤其涉及一种数据请求的方法、装置及系统。The present invention relates to the technical field of the Internet, in particular to a data request method, device and system.
背景技术Background technique
在局域网内部,控制台作为终端与数据库之间的桥梁,负责接收、管理、转发终端向数据库发送的查询请求,并将数据库返回的查询内容下发给终端。通常数据库服务器分配给查询任务的处理资源是有限的,而局域网内瞬时上报的查询请求数量(后续简称为请求并发数)则有可能较大,这种情况下,数据库服务器的处理资源无法对所有的查询请求都进行响应,此时数据库的资源负荷压力较大,容易发生瘫痪。而一旦数据库发生瘫痪就无法进行恢复,只能重启数据库服务器,从而对局域网的正常运行造成中断。Inside the LAN, the console acts as a bridge between the terminal and the database, responsible for receiving, managing, and forwarding the query requests sent by the terminal to the database, and sending the query content returned by the database to the terminal. Usually, the processing resources allocated by the database server to query tasks are limited, and the number of query requests reported instantaneously in the local area network (hereinafter referred to as the number of concurrent requests) may be relatively large. In this case, the processing resources of the database server cannot handle all All query requests are responded to. At this time, the resource load pressure of the database is relatively high, and it is prone to paralysis. Once the database is paralyzed, it cannot be recovered, and the database server can only be restarted, thereby interrupting the normal operation of the local area network.
随着大型企业、机关单位对局域网规模需求的不断增长,局域网中的终端数量将越来越多,网内的查询请求数量也会相应增长,因此数据库瘫痪的频率会越来越高。对于大型网络,特别是多级网络而言,数据库系统的频繁瘫痪势必会影响到网络的稳定性,降低局域网的运行效率。所以,如何对数据库系统进行有效维护,使其能够应对大规模网络环境下的查询需求,就成为摆在技术人员眼前的一道难题。With the continuous growth of large-scale enterprises and institutions, the number of terminals in the LAN will increase, and the number of query requests in the network will increase accordingly, so the frequency of database failure will become higher and higher. For a large network, especially a multi-level network, the frequent failure of the database system will inevitably affect the stability of the network and reduce the operating efficiency of the local area network. Therefore, how to effectively maintain the database system so that it can cope with the query requirements in a large-scale network environment has become a difficult problem for technicians.
发明内容Contents of the invention
有鉴于此,本发明提供一种数据请求的方法、装置及系统,能够解决数据库因查询请求过多而发生瘫痪的问题。In view of this, the present invention provides a data request method, device and system, which can solve the problem of database paralysis due to too many query requests.
为解决上述技术问题,一方面,本发明提供了一种数据请求的方法,该方法包括:In order to solve the above technical problems, on the one hand, the present invention provides a method for data request, the method comprising:
建立对应数据库的第一协程,并通过第一协程对数据库的负荷状态进行检测,获得检测结果;Establish the first coroutine corresponding to the database, and detect the load status of the database through the first coroutine, and obtain the detection result;
在接收到终端上报的查询请求时,建立对应查询请求的第二协程,并通过第二协程向第一协程获取检测结果;When the query request reported by the terminal is received, a second coroutine corresponding to the query request is established, and the detection result is obtained from the first coroutine through the second coroutine;
若检测结果表征数据库处于超负荷状态,则停止向数据库转发查询请求。If the detection result indicates that the database is in an overloaded state, stop forwarding query requests to the database.
另一方面,本发明还提供了一种数据请求的装置,该装置包括:On the other hand, the present invention also provides a device for data request, which includes:
检测单元,用于建立对应数据库的第一协程,并通过第一协程对数据库的负荷状态进行检测,获得检测结果;The detection unit is used to establish the first coroutine corresponding to the database, and detect the load state of the database through the first coroutine to obtain the detection result;
获取单元,用于在接收到终端上报的查询请求时,建立对应查询请求的第二协程,并通过第二协程向检测单元建立的第一协程获取检测结果;The obtaining unit is configured to, when receiving the query request reported by the terminal, establish a second coroutine corresponding to the query request, and obtain the detection result from the first coroutine established by the detection unit through the second coroutine;
处理单元,用于当获取单元获取的检测结果表征数据库处于超负荷状态时,停止向数据库转发查询请求。The processing unit is configured to stop forwarding the query request to the database when the detection result obtained by the obtaining unit indicates that the database is in an overloaded state.
再一方面,本发明还提供了一种数据请求的系统,该系统包括:终端、控制台以及数据库服务器;其中,控制台包括如前述第二方面所指的装置;In another aspect, the present invention also provides a data request system, the system includes: a terminal, a console, and a database server; wherein, the console includes the device referred to in the aforementioned second aspect;
终端,用于向控制台上报查询请求,查询请求用于向数据库服务器请求进行数据查询;The terminal is used to report a query request to the console, and the query request is used to request a data query from the database server;
控制台,用于在检测结果表征数据库处于正常负荷状态时,向数据库服务器转发查询请求,而在检测结果表征数据库处于超负荷状态时,停止向数据库服务器转发查询请求;The console is used to forward the query request to the database server when the detection result indicates that the database is in a normal load state, and stop forwarding the query request to the database server when the detection result indicates that the database is in an overloaded state;
数据库服务器,用于在检测结果表征数据库处于正常负荷状态时,接收控制台转发的查询请求,并对查询请求进行响应,返回查询内容;The database server is used to receive the query request forwarded by the console when the detection result indicates that the database is in a normal load state, respond to the query request, and return the query content;
控制台,还用于接收数据库服务器返回的查询内容,并将查询内容下发给终端。The console is also used to receive the query content returned by the database server and send the query content to the terminal.
本发明提供的数据请求的方法、装置及系统,能够建立一个常驻的第一协程对数据库的负荷状态进行持续检测,并将获得的检测结果共享给为查询请求建立的第二协程,以便后者基于不同的检测结果对查询请求进行转发或取消转发的处理。与现有技术相比,本发明可以在数据库处于超负荷状态时暂停查询请求的转发,能够给予数据库充分的时间对已有请求进行及时处理并释放相应的处理资源,由此防止数据库因查询请求过多而发生瘫痪。The data request method, device and system provided by the present invention can establish a resident first coroutine to continuously detect the load status of the database, and share the obtained detection results with the second coroutine established for the query request, So that the latter forwards or cancels the forwarding of the query request based on different detection results. Compared with the prior art, the present invention can suspend the forwarding of query requests when the database is in an overloaded state, and can give the database enough time to process existing requests in a timely manner and release corresponding processing resources, thereby preventing the database from being overwhelmed by query requests. Too much can lead to paralysis.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。The above description is only an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention, it can be implemented according to the contents of the description, and in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable , the specific embodiments of the present invention are enumerated below.
附图说明Description of 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 embodiment. The drawings are only for the purpose of illustrating a preferred embodiment and are not to be considered as limiting the invention. Also throughout the drawings, the same reference numerals are used to designate the same components. In the attached picture:
图1示出了本发明提供的一种数据请求的方法流程图;Fig. 1 shows a flow chart of a data request method provided by the present invention;
图2示出了本发明提供的另一种数据请求的方法流程图;FIG. 2 shows a flow chart of another data request method provided by the present invention;
图3示出了本发明提供的又一种数据请求的方法流程图;Fig. 3 shows a flow chart of another data request method provided by the present invention;
图4示出了本发明提供的等待队列的示意图;Fig. 4 shows the schematic diagram of the waiting queue provided by the present invention;
图5(a)及图5(b)示出了本发明提供的混合转发查询请求的示意图;Fig. 5 (a) and Fig. 5 (b) have shown the schematic diagram of hybrid forwarding query request provided by the present invention;
图6示出了本发明提供的一种数据请求的装置的结构示意图;Fig. 6 shows a schematic structural diagram of a device for data request provided by the present invention;
图7示出了本发明提供的另一种数据请求的装置的结构示意图;Fig. 7 shows a schematic structural diagram of another data request device provided by the present invention;
图8示出了本发明提供的一种数据请求的系统示意图。Fig. 8 shows a schematic diagram of a data request system provided by the present invention.
具体实施方式Detailed ways
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although 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 by the embodiments set forth herein. Rather, these embodiments are provided for more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
为防止数据库因查询请求过多而发生瘫痪,本发明实施例提供了一种数据请求的方法,该方法能够在数据库处于超负荷状态时暂停查询请求的转发,由此使得数据库有充分的时间对已有请求进行处理。如图1所示,该方法包括:In order to prevent the database from being paralyzed due to too many query requests, the embodiment of the present invention provides a data request method, which can suspend the forwarding of query requests when the database is in an overloaded state, thus allowing the database to have sufficient time to process A request has already been processed. As shown in Figure 1, the method includes:
101、建立对应数据库的第一协程,并通过第一协程对数据库的负荷状态进行检测,获得检测结果。101. Establish a first coroutine corresponding to the database, and detect the load status of the database through the first coroutine, and obtain a detection result.
在启动数据库时,控制台建立一个独立的第一协程,专门用于对数据库的负荷状态进行检测。本实施例中的第一协程为一种常驻协程,即该协程在数据库初始化时建立、并存活于整个数据查询的过程中。无论控制台是否接收终端上报的查询请求,只要数据库的生命周期没有结束,那么第一协程就会一直保持存活状态,对数据库的资源负荷状态进行持续检测。When starting the database, the console creates an independent first coroutine, which is specially used to detect the load status of the database. The first coroutine in this embodiment is a resident coroutine, that is, the coroutine is established when the database is initialized and survives the entire process of data query. No matter whether the console receives the query request reported by the terminal, as long as the life cycle of the database is not over, the first coroutine will keep alive and continuously detect the resource load status of the database.
需要说明的是,本实施例中所述的持续检测,是指一种保持检测状态的过程,并非限定于不间断检测的情况。在实际应用中,上述持续检测的方式还包括:按照某个预设的时间间隔进行周期性检测、或者根据控制台的指令进行不定期检测、再或者基于某种预设策略/规则进行自动检测等,本实施例不对第一协程检测数据库状态的时机、次数或者频率进行限制。It should be noted that the continuous detection described in this embodiment refers to a process of maintaining a detection state, and is not limited to the situation of uninterrupted detection. In practical applications, the above-mentioned continuous detection method also includes: periodic detection according to a certain preset time interval, or irregular detection according to the instructions of the console, or automatic detection based on a certain preset strategy/rule Etc., this embodiment does not limit the timing, number of times or frequency of the first coroutine detecting the state of the database.
在本实施例中,能够反映数据库资源负荷状态的资源参数可以是:内存使用占比、中央处理器(Central Processing Unit,简称CPU)使用占比、磁盘读写接口使用占比等。当然,资源参数也可以是上述几种资源参数的组合。第一协程可以通过预先写好的接口程序向数据库发送数据请求,获取上述资源参数(或资源参数的组合),并通过与预设标准阈值比对的方式获得数据库负荷状态的检测结果。In this embodiment, the resource parameters that can reflect the database resource load status may be: memory usage ratio, central processing unit (Central Processing Unit, CPU for short) usage ratio, disk read-write interface usage ratio, and the like. Of course, the resource parameter may also be a combination of the above resource parameters. The first coroutine can send a data request to the database through a pre-written interface program, obtain the above resource parameters (or a combination of resource parameters), and obtain the detection result of the database load status by comparing with the preset standard threshold.
一般情况下,数据库服务器通常不会将全部的处理资源都分配给数据查询任务,因此在实际应用中,上述各资源参数的使用占比应当是其实际资源分配范围下的使用占比。例如,假设对于4G内存的数据库服务器而言,如果其分配1G内存资源用于处理查询请求,那么当当前处理查询请求占用0.4G内存时,其实际的内存使用占比应当为40%,而非10%。Under normal circumstances, the database server usually does not allocate all processing resources to data query tasks. Therefore, in practical applications, the usage ratio of the above resource parameters should be the usage ratio under the actual resource allocation range. For example, suppose that for a database server with 4G memory, if it allocates 1G memory resources for processing query requests, then when the current processing query request occupies 0.4G memory, its actual memory usage ratio should be 40%, not 10%.
上述获取资源参数的检测方式只是本实施例的一种实现方式之一,实际应用中,控制台也可以不必关心数据库的具体资源参数,而是从结果层面直接对数据库的响应速度进行检测,若数据库的响应速度过慢(用时较长),则表明数据库的资源负荷超过了正常承受能力。换言之,数据库的响应速度能够综合体现其内部各种资源的占用情况,因此在实际应用中,对响应速度进行测试通常实现起来更为简便,并且能够获得更加理想的检测效果。本实施例后续将着重以此种检测方式为例进行说明。The above detection method for obtaining resource parameters is only one of the implementation methods of this embodiment. In practical applications, the console may not care about the specific resource parameters of the database, but directly detects the response speed of the database from the result level. If the response speed of the database is too slow (it takes a long time), it indicates that the resource load of the database exceeds the normal capacity. In other words, the response speed of the database can comprehensively reflect the occupancy of various internal resources. Therefore, in practical applications, it is usually easier to test the response speed, and more ideal detection results can be obtained. This embodiment will focus on taking this detection method as an example for description later.
在本实施例中,控制台获取的检测结果可以具有不同的表现形式。在本实施例的一种实现方式中,检测结果可以是一个能够描述数据库负荷状态的档位等级,例如“空闲”、“繁忙”、“饱和”、“过载”等,不同的档位用于反映数据库不同的负荷程度;或者在本实施例的另一种实现方式中,检测结果也可以是一个简单的数值,例如45、67等,该数值的大小用于反映数据库的负荷程度,对于这种形式,需要保证该数值具有一个存在边界的取值区间,该区间的上下边界应当对应数据库的两种极端负荷程度(例如0负荷及过载等)。而为了简化实际应用中的实施,在本实施例的第三种实现方式中,检测结果仅分为“正常负荷状态”与“超负荷状态”两档,两档之间的界限可由管理员结合网络规模、数据库性能等因素综合考虑并设定得出,也可以由控制台根据预设的规则策略自行计算得出,并可进行动态调整。由于便于实现,因此本实施例后续将以第三种形式的检测结果为例进行说明。In this embodiment, the detection results acquired by the console may have different presentation forms. In an implementation of this embodiment, the detection result may be a gear level that can describe the load status of the database, such as "idle", "busy", "saturated", "overloaded", etc. Different gears are used for Reflect the different load levels of the database; or in another implementation of this embodiment, the test result can also be a simple value, such as 45, 67, etc., the size of the value is used to reflect the load level of the database, for this In this form, it is necessary to ensure that the value has a value range with a boundary, and the upper and lower boundaries of the range should correspond to two extreme load levels of the database (such as zero load and overload, etc.). In order to simplify the implementation in practical applications, in the third implementation of this embodiment, the detection results are only divided into two levels of "normal load state" and "overload state", and the boundaries between the two levels can be combined by the administrator. Factors such as network scale and database performance are comprehensively considered and set, and can also be calculated by the console according to preset rules and policies, and can be dynamically adjusted. Since it is easy to implement, the third form of detection result will be taken as an example for description later in this embodiment.
102、在接收到终端上报的查询请求时,建立对应查询请求的第二协程,并通过第二协程向第一协程获取检测结果。102. When receiving the query request reported by the terminal, establish a second coroutine corresponding to the query request, and obtain a detection result from the first coroutine through the second coroutine.
与现有技术中控制台直接将查询请求转发给数据库不同,本实施例中,控制台在向数据库转发查询请求之前,首先需要通过对应该请求的第二协程向第一协程获取数据库状态的检测结果,当数据库处于超负荷状态时,执行下述步骤103,停止转发查询请求,由此减轻数据库的负荷压力。Different from the console directly forwarding the query request to the database in the prior art, in this embodiment, before the console forwards the query request to the database, it first needs to obtain the database status from the first coroutine through the second coroutine corresponding to the request As a result of the detection, when the database is in an overload state, the following step 103 is performed to stop forwarding query requests, thereby reducing the load pressure on the database.
本步骤中的第二协程是针对查询请求建立的、并独立于前述第一协程的协程。控制台接收到几条查询请求就建立几条第二协程,各条第二协程之间没有实质关联。本实施例中,第二协程基于查询请求的上报而建立,在查询请求获得查询响应后或查询终止时结束,相对于第一协程的存活周期而言,第二协程的存活周期通常较短。The second coroutine in this step is a coroutine established for the query request and independent of the aforementioned first coroutine. When the console receives several query requests, it will establish several second coroutines, and there is no substantial relationship between the second coroutines. In this embodiment, the second coroutine is established based on the report of the query request, and ends after the query request obtains a query response or when the query is terminated. Compared with the life cycle of the first coroutine, the life cycle of the second coroutine is usually shorter.
本实施例中,第一协程专用于检测数据库的负荷状态,不负责向第二协程发送检测结果,因此,第二协程在向数据库转发查询请求时,需要主动向第一协程索取检测结果。实际应用中,控制台侧的请求并发数通常较多,因此每个查询请求对应的第二协程需要分别向第一协程索取检测结果,各条协程索取检测结果的动作是相互独立的,本实施例不限定所有第二协程同时索取检测结果。此外,如前所述,第一协程对数据库的检测是持续性的,基于数据库负荷状态的不断变化,第一协程在不同时间获取的检测结果可能存在差异,而第二协程索取检测结果的时机各自不同,因此实际应用中,不同第二协程获取的检测结果可能不同,例如,请求1的第二协程在前一时段获取的检测结果为“超负荷状态”,而请求2的第二协程在下一时段获取的检测结果则为“正常负荷状态”。基于不同的检测结果,不同查询请求的处理结果当然各有不同。In this embodiment, the first coroutine is dedicated to detecting the load status of the database, and is not responsible for sending the detection result to the second coroutine. Therefore, when the second coroutine forwards the query request to the database, it needs to actively ask the first coroutine for Test results. In practical applications, the number of concurrent requests on the console side is usually large, so the second coroutine corresponding to each query request needs to request the detection result from the first coroutine separately, and the actions of each coroutine to obtain the detection result are independent of each other , this embodiment does not limit all the second coroutines to request the detection results at the same time. In addition, as mentioned above, the detection of the database by the first coroutine is continuous. Based on the continuous change of the database load status, the detection results obtained by the first coroutine at different times may be different, while the second coroutine requests the detection The timing of the results is different, so in actual applications, the detection results obtained by different second coroutines may be different. For example, the detection result obtained by the second coroutine of request 1 in the previous period is "overload state", while the test result of request 2 The detection result obtained by the second coroutine in the next period is "normal load state". Based on different detection results, the processing results of different query requests are of course different.
103、若检测结果表征数据库处于超负荷状态,则停止向数据库转发查询请求。103. If the detection result indicates that the database is in an overloaded state, stop forwarding the query request to the database.
当第二协程获取的检测结果为数据库处于超负荷状态时,控制台停止将该第二协程对应的查询请求发送给数据库。对于该查询请求的后续处理,在本实施例的一种实现方式中,控制台可以将该查询请求丢弃,并通知终端,对于终端而言,相当于本次查询流程结束;而在本实施例的另一种实现方式中,控制台也可以“挂起”该查询请求,当数据库的负荷压力减轻时再转发给数据库。When the detection result obtained by the second coroutine is that the database is in an overload state, the console stops sending the query request corresponding to the second coroutine to the database. For the subsequent processing of the query request, in an implementation of this embodiment, the console can discard the query request and notify the terminal. For the terminal, it is equivalent to the end of the query process; and in this embodiment In another implementation of , the console can also "suspend" the query request, and forward it to the database when the load pressure on the database is reduced.
本步骤中,控制台可以单独建立一个处理协程执行丢弃或挂起请求的操作,实际应用中,控制台可以为每个需要处理的请求单独建立一个处理协程,并在处理完成后结束该处理协程,也可以常驻一个总协程,由该总协程统一对各个查询请求进行处理。In this step, the console can independently establish a processing coroutine to perform the operation of discarding or suspending the request. In practical applications, the console can separately establish a processing coroutine for each request that needs to be processed, and end the process after the processing is completed. The processing coroutine can also be resident in a general coroutine, and the general coroutine processes each query request uniformly.
实际应用中,无论单独建立处理协程还是建立总协程,都会占用控制台一部分处理资源。为尽量避免控制台处理资源的无谓开销,在本实施例的一种实现方式中,控制台可以利用已有的第二协程执行丢弃、挂起请求等操作。In practical applications, no matter whether the processing coroutine is established separately or the general coroutine is established, a part of the processing resources of the console will be occupied. In order to avoid unnecessary overhead of console processing resources, in an implementation manner of this embodiment, the console may use an existing second coroutine to perform operations such as discarding and suspending requests.
104、若检测结果表征数据库处于正常负荷状态,则向数据库转发查询请求。104. If the detection result indicates that the database is in a normal load state, forward the query request to the database.
对于步骤102中获取的检测结果,如果其表征数据库处于正常负荷状态,那么表示数据库的处理资源存在部分闲置,不会因为进一步增加查询请求而发生瘫痪,因此在此情况下,控制台可以将接收的查询请求发送给数据库进行响应,并将数据库返回的查询内容转发给终端,由此完成一次常规的数据查询流程。For the detection result obtained in step 102, if it indicates that the database is in a normal load state, it means that the processing resources of the database are partially idle, and will not be paralyzed due to further increase in query requests. Therefore, in this case, the console can receive The query request is sent to the database for response, and the query content returned by the database is forwarded to the terminal, thus completing a regular data query process.
与步骤103相似的,在本实施例的一种实现方式中,控制台也可以通过对应请求的第二协程完成发送查询请求、转发查询内容等操作。Similar to step 103, in an implementation manner of this embodiment, the console may also complete operations such as sending a query request and forwarding query content through a second coroutine corresponding to the request.
现有技术中,控制台作为终端与数据库之间的中介,仅负责将终端上报的查询请求发送给数据库进行处理,即使数据库的处理资源告急,出现较大的负荷压力,控制台也不会停止发送查询请求。因此数据库很容易因为资源负荷过大发生瘫痪,而一旦数据库发生瘫痪就无法进行恢复,只能对数据库服务器进行重启,由此使局域网的正常运行被中断。而在本实施例中,控制台可以对数据库的负荷状态进行检测,当数据库负荷过大时,暂停发送查询请求,由此给予数据库消化已有请求的机会,防止数据库瘫痪,进而提高局域网运行的稳定性。In the prior art, as an intermediary between the terminal and the database, the console is only responsible for sending the query requests reported by the terminal to the database for processing. Send query request. Therefore, the database is easy to be paralyzed due to excessive resource load, and once the database is paralyzed, it cannot be recovered, and the database server can only be restarted, thereby interrupting the normal operation of the local area network. In this embodiment, the console can detect the load status of the database, and when the database load is too large, it will suspend sending query requests, thereby giving the database a chance to digest existing requests, preventing the database from being paralyzed, and improving the operating efficiency of the local area network. stability.
其次,在本实施例中,控制台能够通过一个常驻的第一协程对数据库进行持续检测,第二协程直接向第一协程“索取”检测结果即可进行后续的处理操作。从技术实现的角度看,第二协程也能够直接对数据库进行检测,但是由于第二协程的数量较多,大量重复的检测操作势必会浪费控制台有限的处理资源。本实施例能够通过“结果共享”的设计思路降低相似操作的重复执行,可以最大限度减少控制台的资源开销。Secondly, in this embodiment, the console can continuously detect the database through a resident first coroutine, and the second coroutine can directly "request" the detection result from the first coroutine for subsequent processing operations. From the perspective of technical implementation, the second coroutine can also directly detect the database, but due to the large number of second coroutines, a large number of repeated detection operations will inevitably waste the limited processing resources of the console. In this embodiment, the repeated execution of similar operations can be reduced through the design idea of "result sharing", and the resource overhead of the console can be minimized.
第三,与现有技术中通过进程或线程执行相应操作相比,本实施例能够通过更为轻量级的协程执行各类操作。由于协程属于纯后台执行的程序,终端前台或数据库服务器完全感知不到其操作的执行,因此除能够节省线程资源外,采用协程还可以降低执行操作对业务运行的影响。Third, compared with performing corresponding operations through processes or threads in the prior art, this embodiment can perform various operations through lighter-weight coroutines. Since the coroutine is a program executed purely in the background, the terminal foreground or database server is completely unaware of the execution of its operation. Therefore, in addition to saving thread resources, the use of coroutines can also reduce the impact of execution operations on business operations.
进一步的,作为对图1步骤101的细化,在本发明的另一实施例中,控制台可以通过第一协程对数据库的响应速度进行检测,从而获得能够综合反映数据库资源状态的检测结果。具体的如图2所示,该方式包括:Further, as a refinement of step 101 in Figure 1, in another embodiment of the present invention, the console can detect the response speed of the database through the first coroutine, so as to obtain a detection result that can comprehensively reflect the status of database resources . Specifically, as shown in Figure 2, the method includes:
201、通过第一协程向数据库发送状态检测报文。201. Send a status detection message to the database through the first coroutine.
该状态检测报文在报文格式上与传统的数据报文相同,其报头需要携带控制台及数据库的IP地址,以分别作为源IP地址和目的IP地址。但与传统数据报文不同的是,该状态检测报文仅用于测试数据库的响应速度,其数据内容对于状态而言并无实际意义,因此管理员可以随意设置报文的数据内容,例如将其数据内容设置为“Hello DB”或者“Test”。The status detection message is the same as the traditional data message in message format, and its header needs to carry the IP addresses of the console and the database as the source IP address and the destination IP address respectively. But different from the traditional data message, the status detection message is only used to test the response speed of the database, and its data content has no practical significance for the state, so the administrator can set the data content of the message at will, for example, the Its data content is set to "Hello DB" or "Test".
需要说明的是,由于状态检测报文的内容无实际意义,因此从节省网络传输带宽的角度考虑,报文的数据内容不应设置过大。实际应用中,其数据量大小控制在几十字节以下较为适宜。It should be noted that, since the content of the status detection message has no practical significance, the data content of the message should not be set too large from the perspective of saving network transmission bandwidth. In practical applications, it is more appropriate to control the data volume below tens of bytes.
如前所述,对数据库状态的检测是一个持续的过程,在数据库的整个生命周期中,控制台会定期或随机进行多次状态检测,因此,控制台发送状态检测报文的次数通常亦不会限定在一次或少数几次。实际应用中,控制台发送状态检测报文的时机由其启动状态检测的时机所决定,状态检测报文的发送次数则通常不少于状态检测的次数。As mentioned above, the detection of the status of the database is a continuous process. During the entire life cycle of the database, the console will periodically or randomly perform multiple status detections. Therefore, the number of times the console sends status detection messages is usually not It will be limited to one or a few times. In practical applications, the timing for the console to send the status detection message is determined by the timing when it starts the status detection, and the number of times the status detection message is sent is usually not less than the number of status detections.
202、启动本地计时并等待接收数据库的响应报文。202. Start local timing and wait for receiving a response message from the database.
203、接收数据库的响应报文并停止计时。203. Receive a response message from the database and stop timing.
在初始化设置时,管理员可以预先设定好数据库回复的内容,与状态检测报文类似,响应报文的内容也并无实际意义,实际应用中可以将其设置为“Im OK”或“So Far SoGood”等。When initializing the settings, the administrator can pre-set the content of the database reply. Similar to the status detection message, the content of the response message has no practical significance. In practical applications, it can be set to "Im OK" or "So Far So Good", etc.
本步骤中,控制台在发送状态检测报文时启动本地计时,其目的在于计算数据库返回响应报文的耗时。在本实施例的一种实现方式中,控制台可以通过第一协程(当然也可以建立单独的协程)调用计时器功能接口启动计时。此外,控制台也可以通过读取系统时钟的方式,获得发送状态检测报文即接收响应报文的时刻值,并基于两时刻值的差值获得数据库的响应耗时。对于后者实现方式,实际应用中控制台可以对硬件主板上的原子时钟进行读取,也可以读取网络侧的系统时钟,本实施对此不做限制。In this step, the console starts local timing when sending the status detection message, the purpose of which is to calculate the time taken for the database to return the response message. In an implementation manner of this embodiment, the console can call the timer function interface to start timing through the first coroutine (of course, a separate coroutine can also be established). In addition, the console can also obtain the time value of sending the status detection message and receiving the response message by reading the system clock, and obtain the response time of the database based on the difference between the two time values. For the latter implementation, in practical applications, the console can read the atomic clock on the hardware main board, and can also read the system clock on the network side, which is not limited in this implementation.
204、对数据库的响应耗时与预设的规定时间进行比对。204. Comparing the response time of the database with the preset specified time.
若数据库的响应耗时大于预设的规定时间,则表明数据库的响应速度未达到控制台要求的响应速度,执行步骤205;若数据库的响应耗时小于或等于预设的规定时间,则表明数据库的响应速度达到控制台要求的响应速度,执行步骤206。If the response time of the database is greater than the preset specified time, it indicates that the response speed of the database has not reached the response speed required by the console, and step 205 is performed; if the response time of the database is less than or equal to the preset specified time, it indicates that the database If the response speed reaches the response speed required by the console, step 206 is executed.
需要说明的是,对于规定时间的设置,除了要考虑终端对延时的敏感程度之外,还应将报文传输所涉及的正常耗时考虑在内。实际应用中,规定时间的设置一般可以限定在ms级别,特殊情况下(例如网络无法容忍丝毫时延),该规定时间的设置也可以趋近于0ms,本实施例不对规定时间的大小进行限制。It should be noted that, for the setting of the specified time, in addition to considering the terminal's sensitivity to delay, the normal time consumption involved in message transmission should also be taken into consideration. In practical applications, the setting of the specified time can generally be limited to the ms level. In special cases (for example, the network cannot tolerate the slightest delay), the setting of the specified time can also be close to 0ms. This embodiment does not limit the size of the specified time .
205、确定数据库处于超负荷状态。205. Determine that the database is in an overloaded state.
206、确定数据库处于正常负荷状态。206. Determine that the database is in a normal load state.
需要说明的是,实际应用中,当数据库负荷较大时,可能存在数据库无法反馈响应报文的情况。此时,控制台一味等待响应报文并不现实。因此针对此种情况,应当制定一套补救方案。在本实施例的一种实现方式中,控制台可以允许管理员设置一个时长门限值,该门限值一般需要大于前述规定时间(例如500ms、1000ms等)。当控制台计时到达该时长门限值时,做一次状态判断,如果还未接收到数据库反馈的响应报文,则控制台停止计时,并执行步骤205,直接确定数据库处于超负荷状态。但对于读取系统时钟的方式,由于其不涉及到本地计时,控制台无法得知数据库的耗时是否超过时长门限值,因此该实现方式并不适用于此补救方案。It should be noted that in practical applications, when the database load is heavy, there may be a situation where the database cannot feed back a response message. At this time, it is unrealistic for the console to blindly wait for the response message. Therefore, for this situation, a set of remedial plans should be formulated. In an implementation manner of this embodiment, the console may allow the administrator to set a duration threshold, and the threshold generally needs to be greater than the aforementioned specified time (for example, 500 ms, 1000 ms, etc.). When the timing of the console reaches the duration threshold, a state judgment is made. If the response message fed back by the database has not been received, the console stops timing and executes step 205 to directly determine that the database is in an overloaded state. But for the method of reading the system clock, since it does not involve local timing, the console cannot know whether the time consumed by the database exceeds the threshold value, so this implementation method is not suitable for this remedy.
实际应用中,在停止向数据库发送查询请求后,如果数据库仍无法消化已有请求,那么可以判定数据库无法正常恢复。此种情况下,为保证局域网的正常运行,可以对数据库服务器进行重启。重启后的数据库将释放所有被占用的处理资源,因此能够恢复对查询请求的正常处理。In practical applications, after stopping sending query requests to the database, if the database still cannot digest existing requests, it can be determined that the database cannot be recovered normally. In this case, to ensure the normal operation of the LAN, the database server can be restarted. The restarted database will release all occupied processing resources, so normal processing of query requests can be resumed.
在判断数据库是否无法正常恢复时,可以以时间维度作为参考标准。控制台获取一个预设的时长阈值,在向数据库发送状态检测报文后,控制台启动本地计时。如若在到达该时长阀值后仍未接收到数据库的响应报文,则判断数据库无法正常恢复,重启数据库服务器。本实施例中,上述时长阈值可以大于前述时长门限值,但本实施例并不对其具体数值进行限定。When judging whether the database cannot be recovered normally, the time dimension can be used as a reference standard. The console obtains a preset duration threshold, and after sending a status detection message to the database, the console starts local timing. If no response message from the database is received after reaching the time threshold, it is judged that the database cannot be recovered normally, and the database server is restarted. In this embodiment, the foregoing duration threshold may be greater than the foregoing duration threshold, but this embodiment does not limit its specific value.
在重启数据库服务器时,控制台可以调用预先写好的重启指令重启数据库服务器。由于控制台始终保持着针对数据库的第一协程,因此控制台可以通过第一协程调取重启数据库服务器的API,获得并执行其中的重启指令。当然本实施例并不限定控制台通过其他协程或线程调用重启指令。When restarting the database server, the console can call the pre-written restart command to restart the database server. Since the console always maintains the first coroutine for the database, the console can call the API for restarting the database server through the first coroutine, obtain and execute the restart command therein. Of course, this embodiment does not limit the console to call the restart instruction through other coroutines or threads.
进一步的,当数据库中的查询请求发生拥塞、导致重启数据库服务器仍无法完全释放掉全部被占用资源时,控制台还可以进一步自行重启控制台服务器。在重启控制台服务器后,控制台已接收的所有查询请求均被丢弃,由此释放被占用的处理资源。此外,在重新建立与终端的连接时,控制台也可以限制连接的终端数,由此进一步协助减轻数据库的负荷压力。与前述重启数据库服务器相似,控制台也可以通过调用相应的重启指令自行重启。Further, when the query request in the database is congested, so that restarting the database server still cannot completely release all occupied resources, the console can further restart the console server by itself. After the console server is restarted, all query requests received by the console are discarded, thus releasing the occupied processing resources. In addition, when re-establishing a connection with a terminal, the console can also limit the number of connected terminals, thereby further helping to reduce the load on the database. Similar to restarting the database server mentioned above, the console can also restart itself by calling the corresponding restart command.
以上实施例对控制台针对不同检测结果执行的不同处理方式进行了说明。在下面的一个实施例中,将给出一种在数据库恢复正常负荷状态后针对以接收请求的处理方式。具体的,如图3所示,该方法包括:The above embodiments have described the different processing modes executed by the console for different detection results. In an embodiment below, a processing method for receiving requests after the database returns to a normal load state will be given. Specifically, as shown in Figure 3, the method includes:
301、建立对应数据库的第一协程,并通过第一协程对数据库的负荷状态进行检测,获得检测结果。301. Establish a first coroutine corresponding to the database, and detect the load status of the database through the first coroutine, and obtain a detection result.
本实施例中,该检测结果表征数据库处于超负荷状态。In this embodiment, the detection result indicates that the database is in an overloaded state.
302、在接收到终端上报的查询请求时,建立对应查询请求的第二协程,并通过第二协程向第一协程获取检测结果。302. When receiving a query request reported by the terminal, establish a second coroutine corresponding to the query request, and obtain a detection result from the first coroutine through the second coroutine.
303、停止向数据库转发查询请求。303. Stop forwarding the query request to the database.
304、各第二协程继续向第一协程获取检测结果。304. Each second coroutine continues to obtain the detection result from the first coroutine.
本步骤中,当查询请求因数据库超负荷而被停止转发时,除将请求直接丢弃外,还可以由控制台将各个查询请求“挂起”。当数据库恢复正常状态时,再继续将“挂起”的查询请求重新转发给数据库。In this step, when the forwarding of the query request is stopped due to the overload of the database, in addition to directly discarding the request, the console can also "suspend" each query request. When the database returns to a normal state, continue to re-forward the "suspended" query request to the database.
需要说明的是,当数据库处于超负荷状态时,对于已经接收的查询请求,控制台可以将其挂起,等待再次转发。但是对于终端新上报的查询请求,控制台应当予以拒绝,否则控制台聚集的请求数量将会不断增长,挤占控制台的处理资源。It should be noted that when the database is overloaded, the console can suspend the received query request and wait for it to be forwarded again. However, the console should reject the newly reported query request from the terminal, otherwise the number of requests gathered by the console will continue to increase, crowding out the processing resources of the console.
由于涉及重新确定数据库的负荷状态,因此各第二协程需要不断获取新的检测结果。实际应用中,各条第二协程定时(例如每隔100ms)向第一协程获取检测结果。当获取到的检测结果反映数据库恢复正常负荷状态时,执行步骤305,重新转发查询请求;而当获取到的检测结果反映数据库仍处于超负荷状态时,继续执行本步骤,等待获取下一次检测结果。实际应用中,第二协程获取检测结果的时间间隔可以与第一协程检测数据库状态的时间间隔保持一致,即保证第一协程每次获得的检测结果均能够被第二协程计时获取,使查询请求能够被尽快转发到数据库进行处理。Since it involves re-determining the load state of the database, each second coroutine needs to continuously obtain new detection results. In practical applications, each second coroutine obtains the detection result from the first coroutine at regular intervals (for example, every 100 ms). When the obtained test result reflects that the database has returned to a normal load state, execute step 305 to re-forward the query request; and when the obtained test result reflects that the database is still in an overloaded state, continue to execute this step and wait for the next test result to be obtained . In practical applications, the time interval for the second coroutine to obtain the detection results can be consistent with the time interval for the first coroutine to detect the state of the database, that is, to ensure that the detection results obtained by the first coroutine every time can be obtained by the second coroutine. , so that query requests can be forwarded to the database for processing as soon as possible.
305、当数据库恢复正常负荷状态时,向数据库转发查询请求。305. When the database returns to a normal load state, forward the query request to the database.
当数据库恢复正常负荷状态时,控制台通过第二协程将等待转发查询请求发送给数据库进行响应,获得查询内容。When the database returns to the normal load state, the console sends the waiting forwarding query request to the database through the second coroutine for response, and obtains the query content.
下面,给出图3的一种实现方式:Below, an implementation of Figure 3 is given:
控制台预先建立一条等待队列以存放被挂起的查询请求。当数据库处于超负荷状态时,控制台将查询请求加入到等待队列中进行等待转发。而当数据库恢复正常负荷状态后,控制台从等待队列的队首开始,按照先进先出的原则,依次将等待队列中的查询请求转发给数据库,直至等待队列清空为止。示例性的,等待队列中的查询请求可以如图4所示。The console pre-establishes a waiting queue to store pending query requests. When the database is overloaded, the console will add query requests to the waiting queue for forwarding. When the database returns to the normal load state, the console forwards the query requests in the waiting queue to the database sequentially, starting from the head of the waiting queue, according to the first-in-first-out principle, until the waiting queue is emptied. Exemplarily, the query requests in the waiting queue may be as shown in FIG. 4 .
进一步的,当等待队列较长时,为防止终端新上报的查询请求等待过久,在一种改进方式中,控制台还可以对等待队列中的查询请求以及新接收的查询请求进行混合转发,由此对两者请求进行并行兼顾。示例性的,如图5所示,请求A代表等待队列中的查询请求,请求B代表终端新上报的查询请求。控制台对两种请求进行交叉转发,例如图5a中所示的“ABABABA…”方式。当然,控制台也可以按照图5b所示的“AAABBBAAABBB…”方式进行批量交叉转发。本实施例不对控制台采用的具体混合方式进行限制。Furthermore, when the waiting queue is long, in order to prevent the newly reported query request from the terminal from waiting too long, in an improved way, the console can also perform mixed forwarding of the query request in the waiting queue and the newly received query request, Thus, both requests are considered in parallel. Exemplarily, as shown in FIG. 5 , request A represents a query request in a waiting queue, and request B represents a query request newly reported by a terminal. The console cross-forwards the two requests, for example, the "ABABABA..." method shown in Figure 5a. Of course, the console can also perform batch cross-forwarding in the manner of "AAABBBAAABBB..." shown in FIG. 5b. This embodiment does not limit the specific mixing mode adopted by the console.
进一步的,对于上述加入队列的实现方式,队列的建立和维护、以及请求的入队出队均会对控制台造成一定的内存占用。在一种更为简单的实现方式中,控制台可以取消等待队列的建立,转而采用随机抢占的方式进行查询请求的转发。在这种方式中,各个请求的第二协程按照前述步骤304的实现方式不断获取最新的检测请求。当第二协程发现数据库恢复正常负荷状态时,立即进行请求转发。各条第二线程抢占转发的执行是相互独立的,请求转发的先后顺序由第二线程启动抢占的先后顺序决定。再进一步的,在数据库恢复正常负荷状态后,对于终端新上报的查询请求,也可以参与随机抢占转发,与被“挂起”的查询请求一同抢占转发的机会。Further, for the above implementation of joining the queue, the establishment and maintenance of the queue, and the enqueueing and dequeueing of requests will all cause a certain amount of memory occupation on the console. In a simpler implementation, the console can cancel the establishment of the waiting queue, and instead use random preemption to forward query requests. In this manner, the second coroutine of each request continuously obtains the latest detection request according to the implementation manner of the aforementioned step 304 . When the second coroutine finds that the database has returned to a normal load state, it forwards the request immediately. The execution of each second thread's preemptive forwarding is independent of each other, and the order of request forwarding is determined by the order in which the second thread starts preemption. Furthermore, after the database returns to the normal load state, the query request newly reported by the terminal can also participate in random preemptive forwarding, and preempt forwarding opportunities together with the "suspended" query request.
需要说明的是,实际应用中,终端并不能够获得表征数据库负荷状态的信息,因此终端无法得知数据库是否处于超负荷状态。在前述各实施例中,终端无需关心数据库的负荷状态,仅仅按照传统方式上报查询请求即可,因而会出现一个问题,即当控制台停止转发查询请求时,终端仍不断上报新的查询请求。当大量的查询请求拥塞在控制台时,容易导致控制台发生崩溃。为防止控制台大量积压查询请求,在本发明的另一各实施例中,当数据库处于超负荷状态时,控制台可以向各个终端下发指示信息,指示终端暂时停止上报新的查询请求,由此使得控制台的请求数量能够得到控制。相应的,当数据库恢复正常负荷状态时,控制台也可以向各个终端下发指示信息,指示终端重新恢复上报查询请求。It should be noted that, in practical applications, the terminal cannot obtain information representing the load state of the database, so the terminal cannot know whether the database is in an overload state. In the above-mentioned embodiments, the terminal does not need to care about the load status of the database, and only needs to report the query request in the traditional way. Therefore, there will be a problem, that is, when the console stops forwarding the query request, the terminal will continue to report new query requests. When a large number of query requests are congested in the console, it is easy to cause the console to crash. In order to prevent a large backlog of query requests in the console, in another embodiment of the present invention, when the database is in an overloaded state, the console can send instruction information to each terminal, instructing the terminal to temporarily stop reporting new query requests, by This keeps the number of requests to the console under control. Correspondingly, when the database returns to a normal load state, the console can also send instruction information to each terminal, instructing the terminal to resume reporting query requests.
进一步的,在现有的局域网架构中,通常管理员可以通过专用的人机交互平台对局域网进行监控。在本发明的又一实施例中,当数据库的负荷状态发生变化时,控制台还可以向管理员平台发送提示信息,以便管理员计时做出相应决策。Furthermore, in the existing local area network architecture, usually administrators can monitor the local area network through a dedicated human-computer interaction platform. In yet another embodiment of the present invention, when the load status of the database changes, the console can also send prompt information to the administrator platform, so that the administrator can make corresponding decisions in time.
例如,当数据库处于超负荷状态时,控制台可以调用预留的功能接口向管理员平台发送提示信息,告知管理员数据库发生拥塞,无法继续进行响应;当数据库恢复正常负荷状态时,控制台同样调用相同的功能接口向管理员平台发送提示信息,告知管理员数据库恢复正常,可以执行查询任务。本实施例中,控制台可以向管理员平台发送用作提示的静态页面,也可以直接调出对话框输出提示信息,或者还可以在工具栏或页面的其他指定区域中显示提示信息,本实施例不对提示信息展示形式进行限制。For example, when the database is in an overload state, the console can call the reserved function interface to send a prompt message to the administrator platform, informing the administrator that the database is congested and cannot continue to respond; when the database returns to a normal load state, the console also Call the same function interface to send a prompt message to the administrator platform, informing the administrator that the database is back to normal and the query task can be performed. In this embodiment, the console can send a static page used as a prompt to the administrator platform, or directly call out a dialog box to output prompt information, or display prompt information in a toolbar or other designated areas of the page. This example does not limit the display form of the prompt information.
进一步的,作为对上述各方法实施例的实现,本发明另一实施例还提供了一种数据请求的装置,该装置可以位于控制台中,或独立于控制台但与控制台之间建立有数据交互关系,用以实现前述各方法实施例。需要说明的是,本实施例中所述的控制台在实际应用中也可以是一个具有网络管理功能的服务器。如图6所示,该装置包括:检测单元61、获取单元62以及处理单元63;其中,Further, as an implementation of the above-mentioned method embodiments, another embodiment of the present invention also provides a device for data request, which can be located in the console, or be independent of the console but establish a data request between the console and the console. The interaction relationship is used to realize the foregoing method embodiments. It should be noted that the console described in this embodiment may also be a server with network management functions in practical applications. As shown in FIG. 6, the device includes: a detection unit 61, an acquisition unit 62, and a processing unit 63; wherein,
检测单元61,用于建立对应数据库的第一协程,并通过第一协程对数据库的负荷状态进行检测,获得检测结果;The detection unit 61 is configured to establish a first coroutine corresponding to the database, and detect the load status of the database through the first coroutine to obtain a detection result;
获取单元62,用于在接收到终端上报的查询请求时,建立对应查询请求的第二协程,并通过第二协程向检测单元61建立的第一协程获取检测结果;The obtaining unit 62 is configured to, when receiving the query request reported by the terminal, establish a second coroutine corresponding to the query request, and obtain the detection result from the first coroutine established by the detection unit 61 through the second coroutine;
处理单元63,用于当获取单元62获取的检测结果表征数据库处于超负荷状态时,停止向数据库转发查询请求。The processing unit 63 is configured to stop forwarding the query request to the database when the detection result obtained by the obtaining unit 62 indicates that the database is in an overload state.
进一步的,处理单元63,用于当获取单元62获取的检测结果表征数据库处于正常负荷状态时,向数据库转发查询请求。Further, the processing unit 63 is configured to forward the query request to the database when the detection result obtained by the obtaining unit 62 indicates that the database is in a normal load state.
进一步的,检测单元61,用于通过第一协程向数据库发送状态检测报文,若未在规定时间内接收到数据库的响应报文,则检测结果为数据库处于超负荷状态。Further, the detection unit 61 is configured to send a status detection message to the database through the first coroutine, and if a response message from the database is not received within a specified time, the detection result is that the database is in an overload state.
进一步的,如图7所示,该装置进一步包括:Further, as shown in Figure 7, the device further includes:
重启单元64,用于当在到达预设的时长阀值后检测单元61仍未接收到数据库的响应报文时,重启数据库服务器;其中时长阀值大于规定时间。The restart unit 64 is configured to restart the database server when the detection unit 61 has not received a response message from the database after reaching a preset time threshold; wherein the time threshold is greater than a specified time.
进一步的,重启单元64,用于通过第一协程调用并执行数据库服务器的重启指令。Further, the restart unit 64 is configured to call and execute a restart instruction of the database server through the first coroutine.
进一步的,处理单元63,用于在数据库服务器恢复正常负荷状态后,将查询请求重新转发给数据库。Further, the processing unit 63 is configured to re-forward the query request to the database after the database server returns to a normal load state.
进一步的,如图7所示,处理单元63,包括:Further, as shown in FIG. 7, the processing unit 63 includes:
第一处理子单元631,用于在停止向数据库转发查询请求后,将查询请求加入到等待队列中,在数据库服务器恢复正常负荷状态后,将等待队列中的查询请求转发给数据库。The first processing subunit 631 is configured to add the query request to the waiting queue after stopping forwarding the query request to the database, and forward the query request in the waiting queue to the database after the database server returns to a normal load state.
进一步的,如图7所示,处理单元63,包括:Further, as shown in FIG. 7, the processing unit 63 includes:
第二处理子单元632,用于向终端下发指示信息,指示终端重新上报查询请求。The second processing subunit 632 is configured to deliver indication information to the terminal, instructing the terminal to re-report the query request.
进一步的,如图7所示,该装置进一步包括:Further, as shown in Figure 7, the device further includes:
调用单元65,用于调用预留的功能接口发送提示信息。The calling unit 65 is used for calling the reserved function interface to send prompt information.
进一步的,作为对上述各方法实施例的实现,本发明另一实施例还提供了一种数据请求的系统。如图8所示,该系统包括:终端81、控制台82以及数据库服务器83。其中,控制台在实际应用中也可以为具有网络管理功能的服务器。该控制台82包括如前图6或图7所示的装置。Furthermore, another embodiment of the present invention also provides a data request system as an implementation of the foregoing method embodiments. As shown in FIG. 8 , the system includes: a terminal 81 , a console 82 and a database server 83 . Wherein, the console may also be a server with network management functions in practical applications. The console 82 includes the devices as previously shown in FIG. 6 or FIG. 7 .
终端81,用于向控制台82上报查询请求,查询请求用于向数据库服务器83请求进行数据查询;The terminal 81 is used to report a query request to the console 82, and the query request is used to request a data query from the database server 83;
控制台82,用于在检测结果表征数据库处于正常负荷状态时,向数据库服务器83转发查询请求,而在检测结果表征数据库处于超负荷状态时,停止向数据库服务器83转发查询请求;The console 82 is used to forward the query request to the database server 83 when the test result indicates that the database is in a normal load state, and stop forwarding the query request to the database server 83 when the test result indicates that the database is in an overloaded state;
数据库服务器83,用于在检测结果表征数据库处于正常负荷状态时,接收控制台82转发的查询请求,并对查询请求进行响应,返回查询内容;The database server 83 is used to receive the query request forwarded by the console 82 when the detection result indicates that the database is in a normal load state, respond to the query request, and return the query content;
控制台82,还用于接收数据库服务器83返回的查询内容,并将查询内容下发给终端81。The console 82 is also used to receive the query content returned by the database server 83 and send the query content to the terminal 81 .
现有技术中,控制台作为终端与数据库之间的中介,仅负责将终端上报的查询请求发送给数据库进行处理,即使数据库的处理资源告急,出现较大的负荷压力,控制台也不会停止发送查询请求。因此数据库很容易因为资源负荷过大发生瘫痪,而一旦数据库发生瘫痪就无法进行恢复,只能对数据库服务器进行重启,由此使局域网的正常运行被中断。而基于本实施例提供的装置及系统,控制台可以对数据库的负荷状态进行检测,当数据库负荷过大时,暂停发送查询请求,由此给予数据库消化已有请求的机会,防止数据库瘫痪,进而提高局域网运行的稳定性。In the prior art, as an intermediary between the terminal and the database, the console is only responsible for sending the query requests reported by the terminal to the database for processing. Send query request. Therefore, the database is easy to be paralyzed due to excessive resource load, and once the database is paralyzed, it cannot be recovered, and the database server can only be restarted, thereby interrupting the normal operation of the local area network. Based on the device and system provided in this embodiment, the console can detect the load status of the database, and when the database load is too large, it will suspend sending query requests, thereby giving the database an opportunity to digest existing requests, preventing the database from being paralyzed, and then Improve the stability of LAN operation.
其次,基于本实施例提供的装置及系统,控制台能够通过一个常驻的第一协程对数据库进行持续检测,第二协程直接向第一协程“索取”检测结果即可进行后续的处理操作。从技术实现的角度看,第二协程也能够直接对数据库进行检测,但是由于第二协程的数量较多,大量重复的检测操作势必会浪费控制台有限的处理资源。本实施例能够通过“结果共享”的设计思路降低相似操作的重复执行,可以最大限度减少控制台的资源开销。Secondly, based on the device and system provided in this embodiment, the console can continuously detect the database through a resident first coroutine, and the second coroutine can directly "request" the detection result from the first coroutine for subsequent Processing operations. From the perspective of technical implementation, the second coroutine can also directly detect the database, but due to the large number of second coroutines, a large number of repeated detection operations will inevitably waste the limited processing resources of the console. In this embodiment, the repeated execution of similar operations can be reduced through the design idea of "result sharing", and the resource overhead of the console can be minimized.
第三,与现有技术中通过进程或线程执行相应操作相比,本实施例提供的装置及系统能够通过更为轻量级的协程执行各类操作。由于协程属于纯后台执行的程序,终端前台或数据库服务器完全感知不到其操作的执行,因此除能够节省线程资源外,采用协程还可以降低执行操作对业务运行的影响。Third, compared with performing corresponding operations through processes or threads in the prior art, the device and system provided by this embodiment can perform various operations through lighter-weight coroutines. Since the coroutine is a program executed purely in the background, the terminal foreground or database server is completely unaware of the execution of its operation. Therefore, in addition to saving thread resources, the use of coroutines can also reduce the impact of execution operations on business operations.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。In the foregoing embodiments, the descriptions of each embodiment have their own emphases, and for parts not described in detail in a certain embodiment, reference may be made to relevant descriptions of other embodiments.
可以理解的是,上述方法及装置中的相关特征可以相互参考。另外,上述实施例中的“第一”、“第二”等是用于区分各实施例,而并不代表各实施例的优劣。It can be understood that related features in the above methods and devices can refer to each other. In addition, "first", "second" and so on in the above embodiments are used to distinguish each embodiment, and do not represent the advantages and disadvantages of each embodiment.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The algorithms and displays presented herein are not inherently related to any particular computer, virtual system, or other device. Various generic systems can also be used with the teachings based on this. The structure required to construct such a system is apparent from the above description. Furthermore, the present invention is not specific to any particular programming language. It should be understood that various programming languages can be used to implement the contents of the present invention described herein, and the above description of specific languages is for disclosing the best mode of the present invention.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood 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 the understanding of this description.
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, in order to streamline this disclosure and to facilitate an understanding of one or more of the various inventive aspects, various features of the invention are sometimes grouped together in a single embodiment, figure, or its description. This method of disclosure, however, is not to be interpreted as reflecting an intention that the claimed invention 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 can understand that the modules in the device in the embodiment can be adaptively changed and arranged in one or more devices different from the embodiment. Modules or units or components in the embodiments may be combined into one module or unit or component, and furthermore may be divided into a plurality of sub-modules or sub-units or sub-assemblies. All features disclosed in this specification (including accompanying claims, abstract and drawings) and any method or method so disclosed may be used in any combination, except that at least some of such features and/or processes or units are mutually exclusive. All processes or units of equipment are combined. Each feature disclosed in this specification (including 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 understand that although some embodiments described herein include some features included in other embodiments but not others, combinations of features from 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.
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的对象流转监控的方法、装置及系统中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present 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 should understand that a microprocessor or a digital signal processor (DSP) can be used in practice to implement some or all of some or all of the object flow monitoring method, device, and system according to the embodiments of the present invention. Full functionality. The present invention can also be implemented as an apparatus or an apparatus program (for example, a computer program and a computer program product) for performing a part or all of the methods described herein. Such a program for realizing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet site, or provided on a carrier signal, or provided 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 can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means can be embodied by one and the same item of hardware. The use of the words first, second, and third, etc. does not indicate any order. These words can be interpreted as names.
Claims (17)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410681632.9A CN104408110B (en) | 2014-11-24 | 2014-11-24 | The method, apparatus and system of request of data |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410681632.9A CN104408110B (en) | 2014-11-24 | 2014-11-24 | The method, apparatus and system of request of data |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104408110A CN104408110A (en) | 2015-03-11 |
CN104408110B true CN104408110B (en) | 2018-11-09 |
Family
ID=52645741
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410681632.9A Active CN104408110B (en) | 2014-11-24 | 2014-11-24 | The method, apparatus and system of request of data |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104408110B (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105117291A (en) * | 2015-06-30 | 2015-12-02 | 百度在线网络技术(北京)有限公司 | Method and system adjusting operation quantity of message push executor |
CN106656604A (en) * | 2016-12-23 | 2017-05-10 | 郑州云海信息技术有限公司 | Microservice request management method, microservice controller and high-concurrence microservice architecture |
CN108551465B (en) * | 2018-03-09 | 2020-06-09 | 平安科技(深圳)有限公司 | Server concurrency control method and device, computer equipment and storage medium |
CN110888947B (en) * | 2018-09-10 | 2023-08-01 | 北京嘀嘀无限科技发展有限公司 | Service request processing method and system |
CN111814024B (en) * | 2020-08-14 | 2021-09-03 | 北京斗米优聘科技发展有限公司 | Distributed data acquisition method, system and storage medium |
CN112181600B (en) * | 2020-10-21 | 2021-07-13 | 甘肃柏隆电子商务科技有限责任公司 | Cloud computing resource management method and system |
CN119226298A (en) * | 2024-12-03 | 2024-12-31 | 浙江大华技术股份有限公司 | A control method for graph database and related equipment |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6405045B1 (en) * | 1996-11-30 | 2002-06-11 | Hyundai Electronics Inds. Co. Ltd. | Dynamic overload control device and method in digital mobile communication system |
CN1756164A (en) * | 2004-09-27 | 2006-04-05 | 松下电器产业株式会社 | Data packet receiving control device and method |
CN101394405A (en) * | 2008-10-22 | 2009-03-25 | 金蝶软件(中国)有限公司 | Method and apparatus for data request processing |
CN102170422A (en) * | 2010-02-25 | 2011-08-31 | 腾讯科技(深圳)有限公司 | Method, device and system for inquiring node |
CN103838849A (en) * | 2014-02-13 | 2014-06-04 | 北京数字天域科技股份有限公司 | Information query method, device and system and data processing method and device |
-
2014
- 2014-11-24 CN CN201410681632.9A patent/CN104408110B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6405045B1 (en) * | 1996-11-30 | 2002-06-11 | Hyundai Electronics Inds. Co. Ltd. | Dynamic overload control device and method in digital mobile communication system |
CN1756164A (en) * | 2004-09-27 | 2006-04-05 | 松下电器产业株式会社 | Data packet receiving control device and method |
CN101394405A (en) * | 2008-10-22 | 2009-03-25 | 金蝶软件(中国)有限公司 | Method and apparatus for data request processing |
CN102170422A (en) * | 2010-02-25 | 2011-08-31 | 腾讯科技(深圳)有限公司 | Method, device and system for inquiring node |
CN103838849A (en) * | 2014-02-13 | 2014-06-04 | 北京数字天域科技股份有限公司 | Information query method, device and system and data processing method and device |
Also Published As
Publication number | Publication date |
---|---|
CN104408110A (en) | 2015-03-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104408110B (en) | The method, apparatus and system of request of data | |
WO2013117136A1 (en) | Capacity-based multi-task scheduling method, device and system | |
US8799454B2 (en) | Behavior based client selection for disparate treatment | |
CN109492018B (en) | A method and device for self-adaptive dynamic adjustment of data synchronization system | |
JP6636142B2 (en) | Scale-out association method and apparatus and system | |
WO2018072687A1 (en) | Resource scheduling method and apparatus, and filtered scheduler | |
WO2017080273A1 (en) | Task management methods and system, and computer storage medium | |
US11144423B2 (en) | Dynamic management of monitoring tasks in a cloud environment | |
WO2011100900A2 (en) | Method for adjusting resources dynamically and scheduling device | |
CN104111877A (en) | A thread resource dynamic allocation system and method based on a thread allocation engine | |
WO2015123974A1 (en) | Data distribution policy adjustment method, device and system | |
WO2020238989A1 (en) | Method and apparatus for scheduling task processing entity | |
CN104461722B (en) | A kind of job scheduling method for cloud computing system | |
CN115617497B (en) | Thread processing method, scheduling component, monitoring component, server and storage medium | |
US9769022B2 (en) | Timeout value adaptation | |
CN108028806A (en) | The method and apparatus that virtual resource is distributed in network function virtualization NFV networks | |
CN103634230A (en) | Dynamic prediction-based network driver layer data packet receiving method and system | |
CN111400214B (en) | Method for realizing dual-core shared network port, intelligent terminal and storage medium | |
JP2016528648A (en) | Network application parallel scheduling to reduce power consumption | |
CN117472570A (en) | Methods, apparatus, electronic devices and media for scheduling accelerator resources | |
CN110659132B (en) | Request processing optimization method and computer-readable storage medium | |
CN115914328B (en) | Network health detection method, device, electronic equipment and storage medium | |
CN105260233A (en) | Application container creating method and apparatus | |
CN115934845A (en) | Self-adaptive data synchronization system, method and storage medium | |
JP2008225641A (en) | Computer system, interrupt control method and program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C41 | Transfer of patent application or patent right or utility model | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20170112 Address after: 100015 Chaoyang District Road, Jiuxianqiao, No. 10, building No. 3, floor 15, floor 17, 1701-26, Applicant after: BEIJING QIANXIN TECHNOLOGY Co.,Ltd. Address before: 100088 Beijing city Xicheng District xinjiekouwai Street 28, block D room 112 (Desheng Park) Applicant before: BEIJING QIHOO TECHNOLOGY Co.,Ltd. Applicant before: Qizhi software (Beijing) Co.,Ltd. |
|
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CP03 | Change of name, title or address | ||
CP03 | Change of name, title or address |
Address after: 100088 Building 3 332, 102, 28 Xinjiekouwai Street, Xicheng District, Beijing Patentee after: QAX Technology Group Inc. Address before: 100015 15, 17 floor 1701-26, 3 building, 10 Jiuxianqiao Road, Chaoyang District, Beijing. Patentee before: BEIJING QIANXIN TECHNOLOGY Co.,Ltd. |