After learning the knowledge of Socket protocol and improving the fixed QPS pressure test model, I plan to conduct a wave of pressure test practice on the socket. IO protocol interface to verify whether there are bugs in my written functions and more room for optimization.

In summary, two or three bugs have been fixed. The calculation method of performance test progress bar has been optimized. Otherwise, in asynchronous processing requests like Socket, the statistical doing() method may take too little time, resulting in calculation errors, which will suddenly jump to the loop display program and directly display 100%, which is also a BUG.

Train of thought

First, a teacher and a student connect socket. IO, then the teacher enters a room (constructs test data in advance) and continuously sends a certain command to get data. Here, a fixed QPS performance test model is adopted. To better describe the performance, I introduced a metric, message response latency, to indicate the Socket service’s ability to handle normal business.

Monitoring thread

The internal static class is still used in the form of the internal static class. It is relatively simple, but Groovy has some problems when accessing static attributes. It took a long time to work out the compiler error. In fact, it is perfectly possible to run Groovy scripts directly, and you can use them without worrying about compiling errors.

/** * Monitoring delay */
    static class ListenThread extends SourceCode implements Runnable {

        public boolean key = true;

        public ScoketIOFunClient listen;

        public List<Long> delays = []

        ListenThread(ScoketIOFunClient listen) {
            this.listen = listen
        }

        @Override
        void run(a) {
            listen.send(OkayScoketConstant.EVENT, getChat(roomId + 1, sbase.uname as long, tbase.uid, kid, ktype, DEFAULT_STRING, true))
            sleep(3.0)
            while (key) {
                def msg = StringUtil.getString(20)
                def start = Time.getTimeStamp()
                listen.send(OkayScoketConstant.EVENT, getChat(roomId + 1, sbase.uname as long, tbase.uid, kid, ktype, msg, true))
                for (int i = 0; i < 10; i++) {
                    def last = listen.msgs.getLast()
                    if (last.contains(msg)) break
                }
                def end = Time.getTimeStamp()
                def l = end - start
                delays << l
                logger.info("Response latency :{}ms", l)
                sleep(3.0)}}public void stop(a) {
            key = false
            Save.saveLongList(delays, "delays")}}Copy the code

Multithreaded task

The mode of FixedQpsThread

is adopted here. Currently, a Socket instance is used globally, and the concurrency is fully satisfied. Because it is asynchronous, there is no pressure.

  • I’m going to cancel hereSocket.IOPrint response messages to prevent too many logs from degrading performance.
static class SendMsg extends FixedQpsThread<ScoketIOFunClient> {

        SendMsg(ScoketIOFunClient scoketIOFunClient) {
            super(scoketIOFunClient, getNum(), getQps(), null.true)}@Override
        protected void doing(a) throws Exception {
            t.send(OkayScoketConstant.EVENT, getCorrect(sbase.getUid(), 1.24.4))}@Override
        FixedQpsThread clone(a) {
           new SendMsg(this.t)
        }
    }
Copy the code

The test script

This is nothing to say, you can read the previous article.

class ST1 extends SocketBase {

    private static Logger logger = LoggerFactory.getLogger(ST1.class)

    static int roomId = 44465

    static int kid = 540

    static int ktype = 1

    static IBase tbase

    static IBase sbase

    static int qps = 200

    static int num = 4000

    public static void main(String[] args) {
        tbase = getTeaBase()
        sbase = getStuBase()
        ScoketIOFunClient teacher = getSocket(tbase)
        ScoketIOFunClient student = getSocket(sbase)

        initAll()
        registerAll()
        joinRoom(roomId)

        teacher.send(OkayScoketConstant.EVENT, getCorrect(sbase.getUid(), 1.24.4))

        def thread = new ListenThread(student)
        def thread1 = new Thread(thread)
        thread1.start()
        new FixedQpsConcurrent(new SendMsg(teacher), "Test message delay under different pressures.").start()

        thread.stop()
        thread1.join()
        leaveRoom(roomId)

        ScoketIOFunClient.closeAll()
    }
}
Copy the code

Console output

INFO->The current user: fv, IP: 10.60.193.37, working directory: / Users/fv/Documents/workspace/okay_test, system coding format: utf-8, Mac OS X system version: 10.16
INFO->Request uri: https://teacherpad- * * *. Cn/API/t_pad/user/login, time-consuming: 985 ms, requestId: Fun20210220090333dMSx
INFO->Teacher: 62951571858, subject: NULL, name: Backpan Xia 626, login successful!
INFO->Request uri: https://stupad-dev * * *. Cn/API/pad/user/login, time-consuming: 187 ms, requestId: Fun20210220090334etdZ
INFO->User: 82951571513, login successful!
INFO->Socket connection: http://aileaidGltZ97Fs&userType=1, client name: teacher :62951571858
INFO->Socket connection: http://1MPkp-zlk&userType=2, client name: Student :82951571513
INFO->Student :82951571513 Start connecting...
INFO->Student :82951571513 connection successful!
INFO->Teacher :62951571858 start connecting...
INFO->Teacher :62951571858 connection successful!
INFO->Compensation thread started!
INFO->Response latency :7ms
INFO->Test under different pressure message delay progress: Man man man man man 20.35%
INFO->Response latency :1ms
INFO->Response latency :1ms
INFO->Expected number of executions :2000, actual number of executions :1652, set QPS:200
INFO->Test the progress of message delay under different pressures: 41.4 percent
INFO->Response latency :1ms
INFO->Response latency :2ms
INFO->Under different pressure test message delay progress: ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ 63.9%
INFO->Response latency :1ms
INFO->Under different pressure test message delay progress: ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ 86.78%
INFO->Response latency :1ms
INFO->Under different pressure test message delay progress: ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ ▍ 100%
INFO->Total 4000 tasks executed, total time: 23.715s, total execution :4133, number of errors :0!
INFO->Data saved successfully! File name: / Users/fv/Documents/workspace/okay_test/long/data/test message delay under different pressure 200903 _1
INFO-> ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ JSON ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ > {> (1). "rt" : 0, > 1). The "total" : 4133, > 1). "QPS" : 6.829, > 1). "failRate" : 0.0, > 1). "threads" : 1, > 1). "startTime" : "the 2021-02-20 09:03:41", > ①. "endTime":"2021-02-20 09:04:04", > ①. "errorRate":0.0, > ①. > < span style = "max-width: 100%; clear: both; min-height: 1em; > 1). "table":"eJzj5VIgDjzb2v1i/dQnO3qfTuh52tf9tGv2kx3dz7Z1PGtc/3T3thf75xsZGFgaGBsSaRwvFy9+m4NSiwvy84pTFUIyc1OtFCp0i1OLMhNzFPJ Kc3UUKnVzU1MyE/MI2UGMS3Iz8xQgplkZKOQW6+QmVlgZAxnE+YIYVWSDR9M6gGjUllFbRm0ZUbY8mtYERPSxCWzFqE2jNo3aNGJtejStFYgop6jpImSzqEO NumjURaMuGnXRqItwuwgADK4ysA = = "" >} ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ JSON ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~INFO-> Test message delay under different pressures 2009031 Response Time: X-Serial Num, Y-median min Median :0 ms, Max :3 ms ****** See the following figure *******

INFO->Data saved successfully! Name of the file: / Users/fv/Documents/workspace/okay_test/long/delays
INFO->Teacher :62951571858 Socket link closed!
INFO->Student :82951571513 Socket link down!
INFO->Close all Socket clients!
INFO->Test message delay progress under different pressures: 0%
INFO->Compensation thread terminated!

Process finished with exit code 0

Copy the code

There are still some problems, such as:

  • QPS calculation error, here is caused by the compensation thread, because it is too fast, the compensation thread should handle these problems, ha ha, I have thisHTTPInterface testing does not have this problem.
  • Due to the short test time, other helper threads are circular mechanism, so the log may be wrong. Such asINFO-> Tests message delay progress under different pressures: 0%This is because after the test task is done, I reset the number of executions to zero0, but the progress bar task is not finished at this time, so I printed one more time. This has confirmed the optimization.
  • There is still room for optimization of the timing and compensation mechanism of the compensation request. The total number of execution 4133 is much higher than the set value 4000. Since it is a fixed amount and then circulates compensation, the task may change at this time, so it needs to be optimized.

Reference article:

  • Exploration of fixed QPS pressure measurement mode
  • Fixed QPS pressure test
  • Asynchronously display test progress in performance tests
  • Client encapsulation based on socket. IO
  • Socket.IO interface multi-user testing practice
  • Socket interface asynchronous authentication practice

FunTester.Authorized author of the Year by Tencent Cloud Community, non-famous test developer ER, welcome to follow.

  • 2020 FunTester self-summary
  • Functional and non-functional testing
  • 17 Common Productivity Skills for Software Testers – Up
  • 17 Productivity Skills used by Software testers – below
  • 7 Steps to becoming a Good Automation Test Engineer
  • Exploration of fixed QPS pressure measurement mode
  • Fixed QPS pressure test
  • Text-based HTTP client in IntelliJ
  • Open source testing service
  • How does the command line execute methods in jar packages
  • The maximum number of consecutive occurrences in a crooked string
  • There is no data to drive automated tests