WO2017162028A1 - 一种模拟线上压力测试的方法和装置 - Google Patents

一种模拟线上压力测试的方法和装置 Download PDF

Info

Publication number
WO2017162028A1
WO2017162028A1 PCT/CN2017/075949 CN2017075949W WO2017162028A1 WO 2017162028 A1 WO2017162028 A1 WO 2017162028A1 CN 2017075949 W CN2017075949 W CN 2017075949W WO 2017162028 A1 WO2017162028 A1 WO 2017162028A1
Authority
WO
WIPO (PCT)
Prior art keywords
requests
time
task queue
request
total number
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
Application number
PCT/CN2017/075949
Other languages
English (en)
French (fr)
Inventor
林江彬
徐彪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Publication of WO2017162028A1 publication Critical patent/WO2017162028A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3409Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment
    • G06F11/3414Workload generation, e.g. scripts, playback
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3409Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment

Definitions

  • the present application relates to the field of information technology, and in particular, to a method for simulating an on-line stress test and a device for simulating an on-line stress test.
  • Stress testing is a test that continuously applies pressure to a system under test by determining the bottleneck of a system or the performance points that cannot be received to obtain the maximum service level test that the system can provide. For example, testing a Web site with a large number of access requests, when the system's response will degenerate or fail. Typically, stress testing is performed by simulating pressure on the line.
  • the principle of the stress test tool is that the client simulates virtual user access through multiple threads or multiple processes, stresses the server side, and then monitors and collects performance data during the process.
  • it is generally implemented by a pressure device.
  • the pressure generating module of the pressure device can generate an actual load according to the content of the script, that is, self-replicating according to the setting of the user to generate multiple clients to send a request to the server.
  • the traditional method of simulating on-line pressure is to create multiple threads from the pressure generation module of the press. In the test, each thread is tested according to the ultimate pressure. Extreme pressure means that each thread initiates a new access request immediately after initiating an access request, or simply reduces the pressure by simply suspending it for a period of time.
  • the traditional method has the following drawbacks:
  • embodiments of the present application have been made in order to provide a method of simulating on-line stress testing and a corresponding apparatus for simulating on-line stress testing that overcomes the above problems or at least partially solves the above problems.
  • the present application discloses a method for simulating an online stress test, including:
  • the step of determining, according to the total number of times of the request, the number of requests corresponding to the multiple time slices, and performing the request of the corresponding time slice according to the number of requests includes:
  • the number of requests corresponding to the plurality of time slices is determined by the total number of requests.
  • the preset test thread is called, and after the current number of requests is read from the task queue, a corresponding number of requests are initiated.
  • the step of invoking a preset test thread, after reading the current number of requests from the task queue, initiating a corresponding number of requests includes:
  • the preset test thread is used, after the current number of requests is read from the task queue, a corresponding request is initiated, and the current number of requests is decremented;
  • the step of obtaining the total number of requests generated in a unit time includes:
  • the total number of requests generated per unit time is sampled from the access log of the device.
  • the step of dividing the unit time into multiple time slices comprises:
  • the unit time is equally divided into a plurality of time slices.
  • an apparatus for simulating an online stress test including:
  • a dividing module configured to divide the unit time into multiple time slices
  • An execution module configured to determine, according to the total number of times of the request, a number of requests corresponding to the multiple time slices, And executing the request of the corresponding time slice according to the number of requests.
  • the execution module includes:
  • determining a submodule configured to determine, by using the total number of requests, a number of requests corresponding to the plurality of time slices.
  • the execution submodule is configured to invoke a preset test thread, and after reading the current number of requests from the task queue, initiate a request for the corresponding number of times.
  • the execution submodule includes:
  • a determining unit configured to invoke a preset test thread, and determine whether the current number of requests in the task queue is zero
  • An execution unit configured to: after determining that the current number of requests in the task queue is not zero, using the preset test thread, after reading the current number of requests from the task queue, initiating a corresponding request, and The current number of requests is decremented;
  • the obtaining module includes:
  • the dividing module includes:
  • the dividing submodule is configured to divide the unit time average into a plurality of time slices.
  • the embodiments of the present application include the following advantages:
  • the unit time is divided into multiple time slices, and the number of requests corresponding to each time slice is respectively determined according to the total number of requests obtained in the unit time, and is executed according to the number of requests.
  • the request of the corresponding time slice can ensure that the number of real requests on the line generated during the stress test on the analog line is consistent; and the manner of determining the number of requests per time slice according to the total number of requests also makes the simulation
  • the pressure generated during the online stress test is controllable.
  • the task queue in the embodiment of the present application is designed to be a value of int type, the memory consumption is extremely low, and the memory requirement is not increased because the number of requests increases, and the corresponding access request is initiated. At the same time, only the current number of requests in the task queue is decremented, further making the scheduling of the test thread efficient and simple.
  • FIG. 1 is a flow chart showing the steps of a first embodiment of a method for simulating an online stress test according to the present application
  • FIG. 2 is a flow chart of steps of a second embodiment of a method for simulating an online stress test according to the present application
  • FIG. 3 is a structural block diagram of an embodiment of an apparatus for simulating an on-line stress test of the present application.
  • FIG. 1 a flow chart of a first embodiment of a method for simulating an online stress test of the present application is shown, which may specifically include the following steps:
  • Step 101 Obtain a total number of requests generated in a unit time
  • the magnitude of the pressure received by the system per unit time can be obtained by sampling, that is, the unit time is generated.
  • the total number of requests is requested to obtain the total number of requests that should be generated for each time period when the stress test on the analog line is performed.
  • the unit time may be a period of time set according to the needs of the sampling, for example, it may be 1s, 5s, 10s or 60s, and the like.
  • a person skilled in the art can set the length of the unit time according to the actual situation that the system is requested on the line, which is not specifically limited in this application.
  • the step of obtaining the total number of requests generated per unit time may include the following sub-steps:
  • Sub-step 1011 sampling the total number of requests generated in a unit time from the access log of the device.
  • the access log of the device can record the request received by the system in real time.
  • the information in the log can be accessed by sampling to obtain the total number of requests generated in a unit time.
  • the system is within 1 s.
  • the total number of requests received was 10,000.
  • Step 102 dividing the unit time into multiple time slices
  • the unit time in order to more accurately control the pressure generated when the pressure test on the analog line is performed, the unit time can be divided into smaller time slices.
  • the unit time average may be divided into multiple time slices, for example, the unit time 1s is equally divided into 100 time slices with a length of 10 ms, or the unit time 1s is equally divided into 1000 lengths of 1 ms. Time slice.
  • a person skilled in the art can determine the length of each time slice according to the specific length of the unit time selected by the sampling, which is not specifically limited in this application.
  • Step 103 Determine, according to the total number of times of the request, a number of requests corresponding to the plurality of time slices, and execute a request for a corresponding time slice according to the number of requests.
  • the number of requests corresponding to the multiple times may be determined by a person in the art according to a random allocation manner, which is not specifically limited in this application. However, it should be noted that no matter how the number of requests for each time slice is determined, it should be ensured that the sum of the number of requests for multiple time slices is the same as the total number of requests obtained per unit time.
  • test thread can be called to execute the request of the corresponding time slice according to the number of requests.
  • the test thread may initiate a corresponding number of requests to the system according to the number of requests of the current time slice.
  • the step of determining the number of requests corresponding to the plurality of time slices according to the total number of times of the request, and performing the request of the corresponding time slice according to the number of requests may be specifically Includes the following substeps:
  • Sub-step 1031 traversing the plurality of time slices
  • Sub-step 1032 determining the number of requests corresponding to the plurality of time slices by using the total number of requests.
  • Sub-step 1033 adding the number of requests to the task queue when the current time slice is executed
  • Sub-step 1034 the preset test thread is invoked, and after the current number of requests is read from the task queue, a request for the corresponding number of times is initiated.
  • the multiple time slices may be traversed, and the number of requests corresponding to each time slice is determined according to the sequence of time slices, and then the number of requests corresponding to the current time slice is added when the current time slice is executed. Go to the task queue, call the preset test thread, and read the current number of requests from the task queue, and then initiate the corresponding number of requests.
  • the number of requests corresponding to the time slice 1 may be added to the task queue, for example, 10 times, and then the test thread is called, and the current request times are read 10 times from the task queue, and the system is Initiate 10 access requests; then execute time slice 2 in chronological order, and request time slice 2
  • the number is added to the task queue, for example 8 times, the test thread is called, the current request number is read 8 times from the task queue, and 8 access requests are initiated to the system; when all the time slices are executed, the test is ended.
  • the unit time is divided into a plurality of time slices, and the number of requests corresponding to each time slice is respectively determined according to the total number of requests obtained in the unit time, and according to the request.
  • the number of times to execute the request of the corresponding time slice can ensure that the number of real requests on the line generated during the stress test on the analog line is consistent; and the manner of determining the number of requests per time slice according to the total number of requests also makes The pressure generated during the pressure test on the analog line is controllable.
  • FIG. 2 a flow chart of the steps of the second embodiment of the method for simulating the online stress test of the present application is shown, which may specifically include the following steps:
  • Step 201 Extracting, from the access log of the device, the total number of requests generated in a unit time
  • the magnitude of the pressure received by the system per unit time can be obtained by sampling first, that is, generated in a unit time.
  • the total number of requests in order to obtain the total number of requests that should be generated for each time period during the stress test on the analog line.
  • the device's access log records the requests received by the system in real time. Therefore, the information in the log can be accessed by the sampling device to obtain the total number of requests generated per unit time. For example, by sampling, the total number of requests received by the system within 1 s per unit time is 10,000 times.
  • Step 202 Average the unit time into a plurality of time slices
  • the unit time in order to more accurately control the pressure generated during the pressure test on the analog line, can be equally divided into smaller time slices.
  • the unit time 1s is equally divided into 100 time slices having a length of 10 ms, or the unit time 1s is equally divided into 1000 time slices having a length of 1 ms.
  • Step 203 Determine, by using the total number of requests, the number of requests corresponding to the multiple time slices.
  • Step 204 Add the number of requests to the task queue when the current time slice is executed.
  • the time sequence of multiple time slices may be followed, first when the time slice 1 is executed.
  • the number of requests corresponding to the time slice 1 is added to the task queue, for example, 10 times.
  • the task pair column in order to ensure the efficient execution of the stress test on the analog line, can be designed as an int type value, and only how many requests in the current time slice need to be initiated.
  • Step 205 Call a preset test thread to determine whether the current number of requests in the task queue is zero.
  • test threads there may be multiple preset test threads, and multiple test threads together form a thread pool.
  • stress test is performed on the analog line, it is executed by multiple test threads in the thread pool.
  • the test thread may, after reading the current number of requests from the task queue, initiate a request for the corresponding number of times.
  • the preset test thread may be invoked, and the current number of requests is read from the task queue to determine whether the current number of requests is zero. If not, step 206 is performed.
  • Step 206 After the current test request is read from the task queue by using the preset test thread, initiate a corresponding request, and decrement the current number of requests.
  • test thread when the test thread determines that the current number of requests in the task queue is not zero, an access request may be initiated and the number of current requests is decremented. For example, if the test thread determines that the current number of requests in the task queue is 10 times when starting the execution of the time slice 1, the access request may be initiated to the system, and then the current number of requests in the task queue is decremented once, that is, After the test thread initiates an access request, the task records the current number of requests in the column as 9 times.
  • the test thread may return to continue to judge the current number of requests in the task queue until the current number of requests is zero, then stop the test or continue to wait for the next time slice. , execute the corresponding number of requests. For example, if the test thread executes the time slice 1 and initiates 10 access requests to the system, so that the current number of requests recorded in the task queue is zero, the next time slice, that is, the time segment corresponding to the time slice 2, can be initiated. The corresponding access request.
  • the task queue is designed to be a value of int type, the memory consumption is extremely low, and the memory requirement is not increased because the number of requests increases, and, when the corresponding access request is initiated. Only the number of current requests in the task queue is decremented, further making the scheduling of test threads efficient and simple.
  • FIG. 3 a structural block diagram of an apparatus for simulating an on-line stress test of the present application is shown, which may specifically include the following modules:
  • the obtaining module 301 is configured to obtain a total number of requests generated in a unit time
  • a dividing module 302 configured to divide the unit time into multiple time slices
  • the executing module 303 is configured to determine, according to the total number of times of the request, the number of requests corresponding to the multiple time slices, and execute the request of the corresponding time slice according to the number of requests.
  • the execution module 303 may specifically include the following sub-modules:
  • the determining submodule 3032 is configured to determine the number of requests corresponding to the plurality of time slices by using the total number of requests.
  • the adding submodule 3033 is configured to add the number of requests to the task queue when the current time slice is executed
  • the execution sub-module 3034 is configured to invoke a preset test thread, and after reading the current number of requests from the task queue, initiate a request for the corresponding number of times.
  • the executing submodule 3034 may specifically include the following units:
  • the determining unit 341 is configured to invoke a preset test thread to determine whether the current number of requests in the task queue is zero;
  • the executing unit 342 is configured to: after determining that the current number of requests in the task queue is not zero, using the preset test thread, after reading the current number of requests from the task queue, initiating a corresponding request, and Decreasing the number of current requests;
  • the returning unit 343 is configured to return to the determining unit when it is determined that the current number of requests in the task queue is zero.
  • the obtaining module 301 may specifically include the following submodules:
  • the obtaining sub-module 3011 is configured to sample the total number of requests generated in a unit time from the access log of the device.
  • the dividing module 302 may specifically include the following submodules:
  • the dividing sub-module 3021 is configured to divide the unit time average into a plurality of time slices.
  • the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
  • embodiments of the embodiments of the present application can be provided as a method, apparatus, or computer program product. Therefore, the embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Moreover, embodiments of the present application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.
  • computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • the computer device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • the memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory.
  • RAM random access memory
  • ROM read only memory
  • Memory is an example of a computer readable medium.
  • Computer readable media includes both permanent and non-persistent, removable and non-removable media.
  • Information storage can be implemented by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disk read only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, Magnetic tape cartridges, magnetic tape storage or other magnetic storage devices or any other non-transportable media can be used to store information that can be accessed by a computing device.
  • computer readable media does not include non-persistent computer readable media, such as modulated data signals and carrier waves.
  • Embodiments of the present application are described with reference to flowcharts and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the present application. It will be understood that each flow and/or block of the flowchart illustrations and/or FIG.
  • These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing terminal device to produce a machine such that instructions are executed by a processor of a computer or other programmable data processing terminal device
  • Means are provided for implementing the functions specified in one or more of the flow or in one or more blocks of the flow chart.
  • the computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device.
  • the instruction device implements the functions specified in one or more blocks of the flowchart or in a flow or block of the flowchart.

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

一种模拟线上压力测试的方法和装置,所述方法包括:获得单位时间内产生的请求总次数(101);将所述单位时间划分为多个时间片(102);根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求(103)。从而能够保证在模拟线上压力测试时产生的请求次数与线上真实的请求次数保持一致;同时,采用根据请求总次数确定每个时间片的请求次数的方式,也使得在模拟线上压力测试时产生的压力是可控的。

Description

一种模拟线上压力测试的方法和装置
本申请要求2016年03月21日递交的申请号为201610161942.7、发明名称为“一种模拟线上压力测试的方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及信息技术领域,特别是涉及一种模拟线上压力测试的方法和一种模拟线上压力测试的装置。
背景技术
压力测试是指对被测系统不断施加压力的测试,是通过确定一个系统的瓶颈或者不能接收的性能点,来获得系统所能提供的最大服务级别的测试。例如,测试一个Web站点在大量的访问请求下,系统的响应何时会退化或失败。通常,压力测试都是通过模拟线上压力来进行的。
压力测试工具的原理是:客户端通过多线程或多进程模拟虚拟用户访问,对服务器端施加压力,然后在过程中监控和收集性能数据。目前,一般采用压力器来实现。压力器的压力产生模块可以根据脚本内容产生实际的负载,也就是根据用户的设置,进行自我复制来生成多个客户端向服务器发送请求。
传统的模拟线上压力的方法是由压力器的压力产生模块创建多个线程,在测试中,每个线程都按照极限压力来进行测试。极限压力的意思是,每个线程在发起一次访问请求后,又立即发起一次新的访问请求,或者只是通过简单的暂停一段时间来减少压力的产生。但是,传统的方法存在如下缺陷:
1)通过压力器创建多个线程,从而产生的压力的次数和频率无法和线上真实压力的次数和频率一致,使得压力测试不能获得理想的结果。
2)通过压力器产生的压力,受软硬件环境影响较大,不同类型或者不同型号的压力器产生的压力差异较大。
3)压力器创建的多个线程相互之间是独立的,每个独立的线程之间没有任何关联,无法按照测试的实际需求去统一地对压力的大小进行控制。
发明内容
鉴于上述问题,提出了本申请实施例以便提供一种克服上述问题或者至少部分地解决上述问题的一种模拟线上压力测试的方法和相应的一种模拟线上压力测试的装置。
为了解决上述问题,本申请公开了一种模拟线上压力测试的方法,包括:
获得单位时间内产生的请求总次数;
将所述单位时间划分为多个时间片;
根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求。
可选地,所述根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求的步骤包括:
遍历所述多个时间片;
采用所述请求总次数确定与所述多个时间片对应的请求次数。
在执行当前时间片时,将所述请求次数添加到任务队列;
调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求。
可选地,所述调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求的步骤包括:
调用预设的测试线程,判断所述任务队列中的当前请求次数是否为零;
若否,则采用所述预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应的请求,并对所述当前请求次数递减;
若是,则返回所述判断所述任务队列中的当前请求次数是否为零的子步骤。
可选地,所述获得单位时间内产生的请求总次数的步骤包括:
从设备的访问日志中抽样提取单位时间内产生的请求总次数。
可选地,所述将所述单位时间划分为多个时间片的步骤包括:
将所述单位时间平均划分为多个时间片。
为了解决上述问题,本申请还公开了一种模拟线上压力测试的装置,包括:
获得模块,用于获得单位时间内产生的请求总次数;
划分模块,用于将所述单位时间划分为多个时间片;
执行模块,用于根据所述请求总次数,分别确定与所述多个时间片对应的请求次数, 并按照所述请求次数执行相应时间片的请求。
可选地,所述执行模块包括:
遍历子模块,用于遍历所述多个时间片;
确定子模块,用于采用所述请求总次数确定与所述多个时间片对应的请求次数。
添加子模块,用于在执行当前时间片时,将所述请求次数添加到任务队列;
执行子模块,用于调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求。
可选地,所述执行子模块包括:
判断单元,用于调用预设的测试线程,判断所述任务队列中的当前请求次数是否为零;
执行单元,用于在判断所述任务队列中的当前请求次数不为零时,采用所述预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应的请求,并对所述当前请求次数递减;
返回单元,用于在判断所述任务队列中的当前请求次数为零时,返回所述判断单元。
可选地,所述获得模块包括:
获得子模块,用于从设备的访问日志中抽样提取单位时间内产生的请求总次数。
可选地,所述划分模块包括:
划分子模块,用于将所述单位时间平均划分为多个时间片。
与背景技术相比,本申请实施例包括以下优点:
本申请实施例,通过将单位时间划分为多个时间片,并根据在所述单位时间内获得的请求总次数,分别确定出与每个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求,能够保证在模拟线上压力测试时产生的请求次数线上真实的请求次数保持一致;同时,采用根据请求总次数确定每个时间片的请求次数的方式,也使得在模拟线上压力测试时产生的压力是可控的。
其次,由于本申请实施例中的任务队列被设计为int类型的值,对内存的消耗极低,不会因为请求次数的增多而增大对内存的要求,而且,通过在发起相应的访问请求时,仅仅是对任务队列中的当前请求次数递减,进一步使得对测试线程的调度高效和简便。
附图说明
图1是本申请的一种模拟线上压力测试的方法实施例一的步骤流程图;
图2是本申请的一种模拟线上压力测试的方法实施例二的步骤流程图;
图3是本申请的一种模拟线上压力测试的装置实施例的结构框图。
具体实施方式
为使本申请的上述目的、特征和优点能够更加明显易懂,下面结合附图和具体实施方式对本申请作进一步详细的说明。
参照图1,示出了本申请的一种模拟线上压力测试的方法实施例一的步骤流程图,具体可以包括如下步骤:
步骤101,获得单位时间内产生的请求总次数;
在本申请实施例中,为了尽可能地保证压力测试中产生的压力与线上真实的压力相一致,可以通过抽样获得单位时间内系统所接收到的压力的大小情况,即单位时间内产生的请求总次数,从而获得在模拟线上压力测试时,每个时间段应该产生的请求总次数。
单位时间可以是根据抽样的需要所设定的一段时间,例如,可以是1s,5s,10s或者60s等等。本领域技术人员可以根据系统在线上被请求的实际情况设定单位时间的长短,本申请对此不作具体限定。
在本申请的一种优选实施例中,所述获得单位时间内产生的请求总次数的步骤可以包括如下子步骤:
子步骤1011,从设备的访问日志中抽样提取单位时间内产生的请求总次数。
通常,设备的访问日志可以实时地记录下系统所接收到的请求,在具体实现中,可以通过抽样提取设备访问日志中的信息,获得单位时间内产生的请求总次数,例如,系统在1s内所接收到的请求总次数为10000次。
步骤102,将所述单位时间划分为多个时间片;
在本申请实施例中,为了更准确地对模拟线上压力测试时产生的压力进行控制,可以将单位时间划分为更小的时间片。
在具体实现中,可以将所述单位时间平均划分为多个时间片,例如,将单位时间1s平均划分为100个长度为10ms的时间片,或者将单位时间1s平均划分为1000个长度为1ms的时间片。本领域技术人员可以根据抽样所选择的单位时间的具体长度,确定每个时间片的长度,本申请对此不作具体限定。
步骤103,根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求。
在本申请实施例中,在确定与所述多个时间片对应的请求次数时,可以按照平均分配的方式,即将在步骤101中获得的请求总次数,平均分配给每个时间片。例如,对于系统在1s内所接收到的请求总次数为10000次,若按照步骤102中的方式,将单位时间1s平均划分成了100个长度为10ms的时间片,则可以确定每个时间片被分配的请求次数为10000/100=100次。
当然,本领域技术人员还可以按照随机分配的方式,确定出与所述多个时间对应的请求次数,本申请对此不作具体限定。但需要注意的是,无论按照何种方式确定每个时间片的请求次数,都应该保证多个时间片的请求次数之和与单位时间获得的请求总次数相同。
进而,在模拟线上压力测试时,可以调用测试线程,按照所述请求次数执行相应时间片的请求。
在具体实现中,在对每个单位时间重放压力的时,测试线程可以按照当前时间片的请求次数,对系统发起相应次数请求。
在本申请的一种优选实施例中,所述根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求的步骤具体可以包括如下子步骤:
子步骤1031,遍历所述多个时间片;
子步骤1032,采用所述请求总次数确定与所述多个时间片对应的请求次数。
子步骤1033,在执行当前时间片时,将所述请求次数添加到任务队列;
子步骤1034,调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求。
在具体实现中,可以遍历所述多个时间片,按照时间片的先后顺序,分别确定出每个时间片对应的请求次数,然后在执行当前时间片时,将当前时间片对应的请求次数添加到任务队列,调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求。
在具体实现中,可以在执行时间片1时,将时间片1对应的请求次数添加到任务队列,例如10次,然后调用测试线程,从任务队列中读取当前请求次数10次,并对系统发起10次访问请求;然后按照时间先后顺序,执行时间片2,将时间片2对应的请求次 数添加到任务队列,例如8次,调用测试线程,从任务队列中读取当前请求次数8次,并对系统发起8次访问请求;当全部时间片均被执行完后,结束所述测试。
在本申请实施例中,通过将单位时间划分为多个时间片,并根据在所述单位时间内获得的请求总次数,分别确定出与每个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求,能够保证在模拟线上压力测试时产生的请求次数线上真实的请求次数保持一致;同时,采用根据请求总次数确定每个时间片的请求次数的方式,也使得在模拟线上压力测试时产生的压力是可控。
参照图2,示出了本申请的一种模拟线上压力测试的方法实施例二的步骤流程图,具体可以包括如下步骤:
步骤201,从设备的访问日志中抽样提取单位时间内产生的请求总次数;
在本申请实施例中,为了尽可能地保证压力测试中产生的压力与线上真实的压力相一致,可以首先通过抽样获得单位时间内系统所接收到的压力的大小情况,即单位时间内产生的请求总次数,从而获得在模拟线上压力测试时,每个时间段应该产生的请求总次数。
通常,设备的访问日志可以实时地记录下系统所接收到的请求。因此,可以通过抽样提取设备访问日志中的信息,获得单位时间内产生的请求总次数,例如,通过抽样,获得系统在单位时间1s内所接收到的请求总次数为10000次。
步骤202,将所述单位时间平均划分为多个时间片;
在具体实现中,为了更准确地对模拟线上压力测试时产生的压力进行控制,可以将单位时间平均划分为更小的时间片。例如,将单位时间1s平均划分为100个长度为10ms的时间片,或者将单位时间1s平均划分为1000个长度为1ms的时间片。
步骤203,采用所述请求总次数确定与所述多个时间片对应的请求次数;
在本申请实施例中,在确定出与所述多个时间片对应的请求次数后,可以按照平均分配的方式,将获得的请求总次数,平均分配给每个时间片。例如,对于系统在单位时间1s内所接收到的请求总次数为10000次,若每个时间片的长度为10ms,则单位时间1s可以被平均划分成100个时间片,进而可以确定每个时间片被分配的请求次数为10000/100=100次。
步骤204,在执行当前时间片时,将所述请求次数添加到任务队列;
在本申请实施例中,可以按照多个时间片的时间先后顺序,首先在执行时间片1时, 将时间片1对应的请求次数,例如10次,添加到任务队列。
在具体实现中,为了保证模拟线上压力测试的高效执行,可以把任务对列设计成一个int类型的值,只记录在当前时间片有多少次的请求需要被发起。
步骤205,调用预设的测试线程,判断所述任务队列中的当前请求次数是否为零;
通常,预设的测试线程可以有多个,多个测试线程共同组成一个线程池,当在模拟线上压力测试时,由线程池中的多个测试线程分别执行。
在本申请实施例中,在调用预设的测试线程后,可以由所述测试线程从所述任务队列中读取当前请求次数后,发起相应次数的请求。
在具体实现中,可以调用预设的测试线程,从所述任务队列中读取出当前请求次数,判断所述当前请求次数是否为零,若否,则执行步骤206。
步骤206,采用所述预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应的请求,并对所述当前请求次数递减。
在具体实现中,当测试线程判断任务队列中的当前请求次数不为零时,可以发起一次访问请求,并对所述当前请求次数递减。例如,若在开始执行时间片1时,测试线程判断任务队列中的当前请求次数为10次,则可以对系统发起一次访问请求,然后对任务队列中的当前请求次数递减一次,即,在所述测试线程发起一次访问请求后,所述任务对列中的当前请求次数记录为9次。
在本申请实施例中,测试线程在发起一次访问请求后,可以返回继续对任务队列中的当前请求次数进行判断,直到当前请求次数为零,则停止所述测试或继续等待在下一个时间片时,执行相应的请求次数。例如,若测试线程在执行时间片1,对系统发起10次访问请求后,使得任务队列中所记录的当前请求次数为零,则需要在下一个时间片即时间片2所对应的时间段才能发起相应的访问请求。
在本申请实施例中,由于任务队列被设计为int类型的值,对内存的消耗极低,不会因为请求次数的增多而增大对内存的要求,而且,通过在发起相应的访问请求时,仅仅是对任务队列中的当前请求次数递减,进一步使得对测试线程的调度高效和简便。
需要说明的是,对于方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请实施例并不受所描述的动作顺序的限制,因为依据本申请实施例,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作并不一定是 本申请实施例所必须的。
参照图3,示出了本申请的一种模拟线上压力测试的装置实施例的结构框图,具体可以包括如下模块:
获得模块301,用于获得单位时间内产生的请求总次数;
划分模块302,用于将所述单位时间划分为多个时间片;
执行模块303,用于根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求。
在本申请实施例中,所述执行模块303具体可以包括如下子模块:
遍历子模块3031,用于遍历所述多个时间片;
确定子模块3032,用于采用所述请求总次数确定与所述多个时间片对应的请求次数。
添加子模块3033,用于在执行当前时间片时,将所述请求次数添加到任务队列;
执行子模块3034,用于调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求。
在本申请实施例中,所述执行子模块3034具体可以包括如下单元:
判断单元341,用于调用预设的测试线程,判断所述任务队列中的当前请求次数是否为零;
执行单元342,用于在判断所述任务队列中的当前请求次数不为零时,采用所述预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应的请求,并对所述当前请求次数递减;
返回单元343,用于在判断所述任务队列中的当前请求次数为零时,返回所述判断单元。
在本申请实施例中,所述获得模块301具体可以包括如下子模块:
获得子模块3011,用于从设备的访问日志中抽样提取单位时间内产生的请求总次数。
在本申请实施例中,所述划分模块302具体可以包括如下子模块:
划分子模块3021,用于将所述单位时间平均划分为多个时间片。
对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。
本领域内的技术人员应明白,本申请实施例的实施例可提供为方法、装置、或计算机程序产品。因此,本申请实施例可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
在一个典型的配置中,所述计算机设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非持续性的电脑可读媒体(transitory media),如调制的数据信号和载波。
本申请实施例是参照根据本申请实施例的方法、终端设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理终端设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理终端设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理终端设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理终端设备上,使得在计算机或其他可编程终端设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程终端设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
尽管已描述了本申请实施例的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例做出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请实施例范围的所有变更和修改。
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者终端设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者终端设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者终端设备中还存在另外的相同要素。
以上对本申请所提供的一种模拟线上压力测试的方法和一种模拟线上压力测试的装置,进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。

Claims (10)

  1. 一种模拟线上压力测试的方法,其特征在于,包括:
    获得单位时间内产生的请求总次数;
    将所述单位时间划分为多个时间片;
    根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求。
  2. 根据权利要求1所述的方法,其特征在于,所述根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求的步骤包括:
    遍历所述多个时间片;
    采用所述请求总次数确定与所述多个时间片对应的请求次数;
    在执行当前时间片时,将所述请求次数添加到任务队列;
    调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求。
  3. 根据权利要求2所述的方法,其特征在于,所述调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求的步骤包括:
    调用预设的测试线程,判断所述任务队列中的当前请求次数是否为零;
    若否,则采用所述预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应的请求,并对所述当前请求次数递减;
    若是,则返回所述判断所述任务队列中的当前请求次数是否为零的子步骤。
  4. 根据权利要求1-3任一所述的方法,其特征在于,所述获得单位时间内产生的请求总次数的步骤包括:
    从设备的访问日志中抽样提取单位时间内产生的请求总次数。
  5. 根据权利要求4所述的方法,其特征在于,所述将所述单位时间划分为多个时间片的步骤包括:
    将所述单位时间平均划分为多个时间片。
  6. 一种模拟线上压力测试的装置,其特征在于,包括:
    获得模块,用于获得单位时间内产生的请求总次数;
    划分模块,用于将所述单位时间划分为多个时间片;
    执行模块,用于根据所述请求总次数,分别确定与所述多个时间片对应的请求次数,并按照所述请求次数执行相应时间片的请求。
  7. 根据权利要求6所述的装置,其特征在于,所述执行模块包括:
    遍历子模块,用于遍历所述多个时间片;
    确定子模块,用于采用所述请求总次数确定与所述多个时间片对应的请求次数;
    添加子模块,用于在执行当前时间片时,将所述请求次数添加到任务队列;
    执行子模块,用于调用预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应次数的请求。
  8. 根据权利要求7所述的装置,其特征在于,所述执行子模块包括:
    判断单元,用于调用预设的测试线程,判断所述任务队列中的当前请求次数是否为零;
    执行单元,用于在判断所述任务队列中的当前请求次数不为零时,采用所述预设的测试线程,从所述任务队列中读取当前请求次数后,发起相应的请求,并对所述当前请求次数递减;
    返回单元,用于在判断所述任务队列中的当前请求次数为零时,返回所述判断单元。
  9. 根据权利要求6-8任一所述的装置,其特征在于,所述获得模块包括:
    获得子模块,用于从设备的访问日志中抽样提取单位时间内产生的请求总次数。
  10. 根据权利要求9所述的装置,其特征在于,所述划分模块包括:
    划分子模块,用于将所述单位时间平均划分为多个时间片。
PCT/CN2017/075949 2016-03-21 2017-03-08 一种模拟线上压力测试的方法和装置 Ceased WO2017162028A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610161942.7 2016-03-21
CN201610161942.7A CN107220165B (zh) 2016-03-21 2016-03-21 一种模拟线上压力测试的方法和装置

Publications (1)

Publication Number Publication Date
WO2017162028A1 true WO2017162028A1 (zh) 2017-09-28

Family

ID=59899208

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/075949 Ceased WO2017162028A1 (zh) 2016-03-21 2017-03-08 一种模拟线上压力测试的方法和装置

Country Status (3)

Country Link
CN (1) CN107220165B (zh)
TW (1) TWI734746B (zh)
WO (1) WO2017162028A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111352967A (zh) * 2020-02-27 2020-06-30 携程旅游网络技术(上海)有限公司 滑动窗口算法的频次控制方法、系统、设备及介质
WO2021042919A1 (zh) * 2019-09-06 2021-03-11 深圳壹账通智能科技有限公司 高并发下的数据分配测试方法、装置、终端及存储介质

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108574610B (zh) * 2018-01-30 2020-10-20 北京金山云网络技术有限公司 一种压力测试方法、装置、电子设备及介质
CN110874304A (zh) * 2018-09-03 2020-03-10 广州神马移动信息科技有限公司 压力测试方法、装置、设备及计算机可读存储介质
CN110865913B (zh) * 2019-11-05 2024-05-03 深圳前海微众银行股份有限公司 一种压力测试的方法及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101639792A (zh) * 2008-07-29 2010-02-03 阿里巴巴集团控股有限公司 一种并发数据处理方法、装置及一种电子记账系统
CN101848116A (zh) * 2010-04-21 2010-09-29 中国海洋大学 一种简单快捷自动的Web服务器压力测试方法
CN103312553A (zh) * 2012-03-14 2013-09-18 百度在线网络技术(北京)有限公司 网站服务质量测试方法及装置
CN105094986A (zh) * 2015-07-20 2015-11-25 暨南大学 一种面向存储系统的突发访问行为的预测方法及装置

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TW200715111A (en) * 2005-10-07 2007-04-16 Inventec Corp Test method of multi-line network pressure
JP5284791B2 (ja) * 2005-12-16 2013-09-11 インターナショナル・ビジネス・マシーンズ・コーポレーション 処理能力のリアル・タイム・ベンチマーキングに基づきソフトウェア製品の使用量を測定する方法、システムおよびコンピュータ・プログラム
US9015188B2 (en) * 2011-09-28 2015-04-21 Bmc Software, Inc. Methods and apparatus for monitoring execution of a database query program

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101639792A (zh) * 2008-07-29 2010-02-03 阿里巴巴集团控股有限公司 一种并发数据处理方法、装置及一种电子记账系统
CN101848116A (zh) * 2010-04-21 2010-09-29 中国海洋大学 一种简单快捷自动的Web服务器压力测试方法
CN103312553A (zh) * 2012-03-14 2013-09-18 百度在线网络技术(北京)有限公司 网站服务质量测试方法及装置
CN105094986A (zh) * 2015-07-20 2015-11-25 暨南大学 一种面向存储系统的突发访问行为的预测方法及装置

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021042919A1 (zh) * 2019-09-06 2021-03-11 深圳壹账通智能科技有限公司 高并发下的数据分配测试方法、装置、终端及存储介质
CN111352967A (zh) * 2020-02-27 2020-06-30 携程旅游网络技术(上海)有限公司 滑动窗口算法的频次控制方法、系统、设备及介质
CN111352967B (zh) * 2020-02-27 2024-02-06 携程旅游网络技术(上海)有限公司 滑动窗口算法的频次控制方法、系统、设备及介质

Also Published As

Publication number Publication date
TWI734746B (zh) 2021-08-01
CN107220165A (zh) 2017-09-29
TW201734785A (zh) 2017-10-01
CN107220165B (zh) 2020-08-04

Similar Documents

Publication Publication Date Title
WO2017162028A1 (zh) 一种模拟线上压力测试的方法和装置
CN106202235B (zh) 一种数据处理方法及装置
WO2017028697A1 (zh) 计算机集群的扩容和缩容方法及设备
TWI755415B (zh) 雲端環境下應用集群資源分配的方法、裝置和系統
WO2017101701A1 (zh) 一种任务状态的查询方法和装置
CN111782404B (zh) 一种数据处理方法及相关设备
CN106708818A (zh) 一种压力测试方法和系统
WO2017084505A1 (zh) 一种获得应用集群容量的方法和装置
CN106933887A (zh) 一种数据可视化方法及装置
WO2022041672A1 (zh) 分布式数据库系统的全量备份方法、装置及计算机可读存储介质
CN109033365B (zh) 一种数据处理方法及相关设备
TW201816627A (zh) 資源調度的方法、裝置和系統
JP2019510305A (ja) データ集約方法および装置
CN108228443B (zh) 一种web应用的测试方法及装置
CN112564996B (zh) 压力测试流量调度、控制方法、设备以及计算机可读介质
CN106293890B (zh) 一种基于复杂度的业务处理方法和装置
CN105302700B (zh) 一种记录在触摸终端上的用户操作的方法与设备
CN110795215A (zh) 一种数据处理方法、计算机设备、存储介质
CN107153601A (zh) 单元性能测试方法及设备
US12547384B2 (en) Web application telemetry
CN117539754A (zh) 压力测试方法、装置、存储介质及电子设备
CN107562533A (zh) 一种数据加载处理方法及装置
Basheer Riskhan Virtual machine performance approaches in the online education system
CN114138619A (zh) 软件并发运行数量测试方法及装置
US11579993B2 (en) Regression testing of computer systems using recorded prior computer system communications

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17769305

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 17769305

Country of ref document: EP

Kind code of ref document: A1