Quietly Mimi improves team happiness & surprise!

Time:2020-9-28

preface

The inspiration of this article is when I was not busy working (fishing) a few months ago. It is meaningless to rush forward alone. I need to think of some ways to improve the efficiency of the team and the happiness of the team (if the efficiency gets up, more code is written per unit time, it is not happiness )After several months of exploration, summed up a few points, if you have a better way, welcome to discuss~

<br/>

I don’t know what version it is

Our products are mainly divided into SaaS end and private platform, which are deployed in the public network and the private environment of customers respectively. Let’s talk about the problems of private environment firstDon’t know which version of the project is actually deployedIt’s ridiculous to say that the operation and maintenance students must have recorded the code versions of each customer during the deployment, but it is so ridiculous that sometimes they make mistakes, which may be due to the imperfect upgrade process or work mistakes. In short, we should try to find a solution.

<br/>

People are unreliable, but there is code.GitIt has become the de facto standard of code management, so I won’t say much about it. That is, if people can’t manage versions well, they still have to start fromGitStart with yourself, quietly Mi’s dependence on all projects(POM.XML)Add a plug-in:

<! -- git version plug-in -- >
<plugin>
    <groupId>pl.project13.maven</groupId>
    <artifactId>git-commit-id-plugin</artifactId>
    <version>4.0.0</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <phase>initialize</phase>
            <goals>
                <goal>revision</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
        <verbose>false</verbose>
        <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
        <prefix>git</prefix>
        <generateGitPropertiesFile>true</generateGitPropertiesFile>
        <generateGitPropertiesFilename>${project.build.outputDirectory}/${project.name}.build.json</generateGitPropertiesFilename>
        <format>json</format>
        <gitDescribe>
            <skip>false</skip>
            <always>false</always>
            <dirty>-dirty</dirty>
        </gitDescribe>
    </configuration>
</plugin>

The plug-in will generate a version related file each time it is built. The contents are as follows:

{
  "git.branch" : "master",
  "git.build.host" : "Kerwin",
  "git.build.time" : "2020-08-12 23:24:59",
  "git.build.user.email" : "[email protected]",
  "git.build.user.name" : "kkzhilu",
  "git.build.version" : "1.0.0-SNAPSHOT",
  "git.closest.tag.commit.count" : "",
  "git.closest.tag.name" : "",
  "git.commit.id" : "4981afb5dfeee6f835dcf9a7a135083d8e973090",
  "git.commit.id.abbrev" : "4981afb",
  "git.commit.id.describe" : "4981afb",
  "git.commit.id.describe-short" : "4981afb",
  "git.commit.message.full" : "Commit git-version",
  "git.commit.message.short" : "Commit git-version",
  "git.commit.time" : "2020-08-04 18:18:47",
  "git.commit.user.email" : "[email protected]",
  "git.commit.user.name" : "kexianming",
  "git.dirty" : "false",
  "git.local.branch.ahead" : "0",
  "git.local.branch.behind" : "0",
  "git.remote.origin.url" : "https://github.com/kkzhilu/KerwinBoots.git",
  "git.tags" : "",
  "git.total.commit.count" : "9"
}

The name of the plug-in is:git-commit-id-pluginAs for the details, you can search by yourself. The effect it can achieve is to generate the corresponding git related information every time you package, so that we can know whether the operation and maintenance students upgrade the code wrongly or notWhat version of code is it

Later, I finally couldn’t hear the quarrel between colleagues because of the code version

<br/>

How to solve the problem of not logging permanently

Back to the SaaS side production environment just mentioned, for various reasons, our team often needs to maintain projects that are not written by ourselves. Many times, some details and logic are completely out of my head, and there is no log. What’s more, the most important thing is that it doesn’t recur in the test environment. What should we do?

<br/>

In the past, the solution was to yell people, then look at the code to find the context and find clues as far as possible. In short, the efficiency is very moving. If the processing is slow, it is an accident. If the whole staff is criticized, what should we do? I have been looking for solutions to this problem, and finally I found a artifact:Arthas

<br/>

People who have used this tool will know how powerful it ishttps://arthas.gitee.io/comma…

We can provide some commands, such as:ttIt can record the input parameters and return information of each call of the specified methodThink about how helpful it is,Record the input and output parameters of each methodIf you do not have a log, you can quickly locate the problem if you know this information with the code. So, if you have heard of it, you can try it. It’s really invincible.

The next time a colleague is in trouble, you can use this tool to help him. He may invite you to dinner

<br/>

Permanently solve the problem of where it takes so long

This problem is due to a previous colleague rewriting a piece of business logic. As a result, the online presentation layer takes about 30 seconds. Oh, my God! In the test environment, it is obviously instantaneous, what to do?

The reason for this problem must be that the SQL is not written well, or there are many unnecessary actions in the business processing (we do not have gray scale test), but the production environment can not be moved at will, nor can we debug the breakpoints. From the log, we can only see that it takes a long time, but we don’t know how slow it is.

<br/>

After n internal methods have passed through a method, you don’t know which one is causing such a long time-consuming. What to do when it can’t be reproduced? In fact, we still use the tool aboveArthasIt’s the same orderttIt can not only record the information of input and output parameters,You can also record the time spent on each methodHow powerful.

<br/>

So I’m here to remind you again that these features are justArthasWe should learn how to use open source tools reasonably

<br/>

The effect diagram of the solution that cannot be expressed by annotation

Annotation is text, and it is difficult to express the effect of flow chart, so what should be done? I have found two solutions, and the effect is very good in the project. The first time is to useASCII annotation tool, address of the tool:http://asciiflow.com/

The results are as follows:

Quietly Mimi improves team happiness & surprise!

The notes are as follows:

+-------------------------------+
|                               |
|  +-------------------------+  |
|  |                         |  |
|  |           Demo          |  |
|  |                         |  |
|  |                         |  |
|  +------------+------------+  |
|               |               |
|               |               |
|               |               |
|               |               |
|               |               |
|               |               |
|               |               |
|               |               |
|               |               |
|               +------> False  |
|               |               |
|               |               |
|    True   <---+               |
|                               |
+-------------------------------+

The drawings drawn by this device can be directly copied into text. Controlling the size can solve most of the situations. You can also imagine whether some wonderful notes on the Internet were drawn with this tool or the same principle. Attach a picture missing from the previous article:

How to play deep paging for hundreds of millions of data? Compatible with MySQL + es + mongodb:https://juejin.im/post/685003…

At the end of this article, I didn’t draw the diagram of my own scheme, so many friends asked me that I couldn’t achieve anything with ID. this time, I’d like to show my scheme by the way

Quietly Mimi improves team happiness & surprise!

The second solution is to useMarkDownI don’t know whether the platform for publishing articles does not support the original drawing function, so I replaced it with screenshots(Typora support

Quietly Mimi improves team happiness & surprise!

If you don’t know, search it,MarkDownDrawing grammar, take a suitable change, there is no need to learn it, put it in the code to see the effect:

Quietly Mimi improves team happiness & surprise!

There is a small oneTipsWhen using idea,You can copy by block using the mouse scroll key, so that you can copy directly to the specified annotation contentAnd then copy it to any of the normal onesMarkDownIn the tool, you can display the flow chart, which is not perfect. If you want to test, you can copy the following code and try it in some tools. You need to set the code type as follows:mermaid

sequenceDiagram
    Note over boot: boot class
    Note over pdfthread: Thread Class
    Note over pdfworker: execution class
      Boot - > > pdfthread: boot class starts thread
    Pdfthread - > > pdfworker: thread class calls real worker
    Loop queue processing
        Pdfthread - > pdfthread: a solution considering success and failure
    end
    
    Pdfworker > > pdfthread: worker response execution results
    Note right of pdfworker: pay attention to parameter verification < br / > file format verification

Your future colleagues will fall in love with you when they maintain the code, and if they are girls, they may marry you

Imagine one day your boss came to ask you, what are the notes you wrote, and then as soon as you copy and paste, a picture will come out! Will there be no you for the next pay rise?

(after all, I’ve gone up a lot)

<br/>

PS: I’d like to write one that supports direct copy and then render to a flowchartIdea plug inIf there are ready-made ones, please contact me to save me from writing A kind of

<br/>

Solution of garbage SQL

Our company has no specialDBA, soSQLThe quality of the statement is only in the hands of the development and development team leader. Sometimes things are too much, or they are not careful, or the module is not very important, it is easy to be careless. When there is a big problem in the production environment, the solution to this situation is still to look for tools. For example, I am interested in itXiaomi’s’ soar ‘

Project address:https://github.com/XiaoMi/soar

Official introduction:

  • Cross platform support
  • At present, it only supports SQL optimization of MySQL syntax family protocol
  • Support sentence optimization based on heuristic algorithm
  • Multi column index optimization supporting complex queries (update, insert, delete, select)

Post a picture to show the effect:

Quietly Mimi improves team happiness & surprise!

This tool can be used to correctSQLWe have not worked out the upper limit of its ability, but the lower limit is still certain, so we only need to pay attention to it laterIndexesIf it is used correctly, the rest will be handed over to this tool. If the score is lower than 90, it will be changed!

PS: this open source project is recommendeddockerInstallation, simple and crude, no brain save time, command as follows:

#Install image
docker pull becivells/soar-web

#Operation
docker run -d --name Soar-web -p 5077:5077 becivells/soar-web

I want to have a tool to check the quality of SQL. Is it true that I am more serious when I write it? I am full of happiness tips, ha ha~

<br/>

Solutions to lazy document writing

It is impossible to write the design documents by tools, but simple database field mapping or interface documents do not need to be developed? In the same way, we have found a few open source projects that are not suitable for the project, but close to the side, such as:

apidoc:https://github.com/apidoc/apidoc

RESTful web API Documentation Generator.

<br/>

JApiDocs:https://github.com/YeDaxia/JA…

A magical api documentation generator without annotation for springboot.

<br/>

APIAuto:https://github.com/TommyLemon…

Machine learning test, automatic code generation, automatic static inspection, automatic generation of documents and comments, etc., to be the most advanced interface management tool

<br/>

Because the situation of each project is different, but I don’t want to make major changes, so it can only be said that it is marginal and can not be 100% suitable. However, with these open source projects, I can rewrite the code to adapt to the annotation scheme of the current project, and so on, which can always save a considerable part of the time of writing documents

<br/>

Solutions to repetitive code

This is really a big hole. Who let us be crud programmers? We often need to write highly repetitive code, but there is a little different code. Here, my solution is to use template + more appropriate tools. If there is a lot of duplicate code in the database operation layer, we can use itmybatis-plusTools reduce duplication of code, or writeCommon operation layerReduce duplicate code.

<br/>

When I can’t use the tool, I will use the template. For example, I wrote a simple open source project:

It looks like a great generator! One project in a second:https://juejin.im/post/684490…

The core ideas and requirements are as follows:

  • Get original data based on Database
  • Based on the template + original data to generate a runnable springboot project, supporting interface + basic addition, deletion, modification and query
  • It can generate new files without modifying the code

<br/>

Using this idea, we can actually write a more open code generation template, for example, according to theJSONMessage to parse data, according to the transmittedTemplateTo generate data, so that you can solve a large part of the repetitive tools, you, are worth having.

PS: similarly, in fact, database field mapping documents can also be used in this way. It only takes one second, which is not too comfortable ♂️

<br/>

Script code for repetitive operations

In fact, we all have awareness of this, but sometimes we feel that we may not use it much. When we really want to use it, we don’t have time to write scripts, such as entering a scriptdockerIf you use the command line, the container will take at least two steps of code, more than ten seconds. If you write a script, it will only take one second to enter the container. So I wrote a lot of such scripts to the team. In fact, I didn’t do it at the beginning. Anyway, I copied one and changed it. The following is the entryDocker containerOf

#Use instructions to prompt for input parameters
usage() {
    Echo "usage: SH execute script.sh [rpcapp|tomcat|nginx| MySQL]"
    exit 1
}

rpcapp(){
  DOCKER_ID=$(docker ps | grep "rpcapp" | awk '{print $1}')
  docker exec -it $DOCKER_ID bash
}

tomcat(){
  DOCKER_ID=$(docker ps | grep "tomcat" | awk '{print $1}')
  docker exec -it $DOCKER_ID bash
}

nginx(){
  DOCKER_ID=$(docker ps | grep "nginx" | awk '{print $1}')
  docker exec -it $DOCKER_ID bash
}

mysql(){
  DOCKER_ID=$(docker ps | grep "mysql" | awk '{print $1}')
  docker exec -it $DOCKER_ID bash
}

#According to the input parameters, select the corresponding method to execute. If no input, the instruction will be executed
case "$1" in
  "rpcapp")
    rpcapp
    ;;
  "tomcat")
    tomcat
    ;;
  "nginx")
    nginx
    ;;
  "mysql")
    mysql
    ;;
  *)
    usage
    ;;
esac

<br/>

I searched the Internet and found an open source project to record common scripts

useful-scripts:https://github.com/oldratlee/…

Quietly Mimi improves team happiness & surprise!

Can automatically do not write every time, save time to fish is not happy

<br/>

last

This is a time management artifact that I have summed up for so long. The time saved can be used to fish and learn. The cycle can promote efficiency and ability and form positive feedback

It’s not worth itGive me a complimentIs that right? Hey, hey~

You can also search the official account.It’s Kerwin“Progress together!

You can also viewKerwin’s GitHub home pagePay attention to the progress of a little white programmer. This product is struggling with go recently~