SpringBoot-IDE工具

IntelliJ IDEA 2019.2.4 x64 工具

IDEA 激活

IntelliJ IDEA2019.1.1激活码

idea maven pom 文件加速

settings.xml 配置

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <pluginGroups />
    <proxies />
    <servers />

    <localRepository>E:/Program Files (x86)/JetBrains/IntelliJ IDEA 2019.2.4/plugins/maven/lib/maven3</localRepository>

    <mirrors>
        <!-- 华为 -->
        <mirror>
            <id>maven.net.cn</id>
            <name>oneof the central mirrors in china</name>
            <url>https://mirrors.huaweicloud.com/repository/maven/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>
</settings>

相关资料

加快IDEA中MAVEN的pom文件下载资源的速度
AliRepo

websocket-压力测试

websocket 长连接数、 websocket压力测试

  • JMeterPlugins-Standard
  • serverAgent

JMeter webscoket 分布式压力测试

  • master:司令
  • slave(server):奴隶
  • target:目标

Jmeter分布式压测原理

  1. 总控机器的节点master,其他产生压力的机器叫“肉鸡” server
  2. master会把压测脚本发送到 server上面
  3. 执行的时候,server上只需要把jmeter-server打开就可以了,不用启动jmeter
  4. 结束后,server会把压测数据回传给master,然后master汇总输出报告

  1. 在master和slaves机器上分别按照相同版本的jdk和jmeter
  2. 在master机器上
    1) 修改配置文件,进入jmeter/bin目录下

vim jmeter.properties

remote_hosts=192.168.0.102:8899,192.168.0.101:8899(slaves机器的ip和端口)
server.rmi.ssl.disable=true(禁用ssl)

如果master即作为master也作为slaves

remote_hosts=192.168.0.102:8899,192.168.0.101:8899,master的ip:8899

server_port=8899

server.rmi.ssl.disable=true(禁用ssl)

2) 启动jmeter服务

./jmeter-server(linux)

jmeter-server.bat(windows)

3) 检查是否启动成功

ps -ef|grep jmeter-server

  1. 在slaves机器上
    1) 修改配置文件,进入jmeter/bin目录下
vim jmeter.properties

remote_hosts=127.0.0.1

server_port=8899

server.rmi.ssl.disable=true(禁用ssl)

2) 启动jmeter服务

./jmeter-server(linux)

jmeter-server.bat(windows)

3) 检查是否启动成功

ps -ef|grep jmeter-server

  1. 分布式执行
    GUI模式 :运行——》远程启动、远程启动全部

non-GUO模式:命令行增加-r参数

jmeter -n -t /Users/jack/Desktop/remote.jmx -r -l /Users/jack/Desktop/jtl/result.jtl -e -o /Users/jack/Desktop/result

JMeter分布式部署遇到的报错问题

Error in rconfigure() method java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: eu.luminis.jmeter.wssampler.OpenWebSocketSampler (no security manager: RMI class loader disabled)
  • 情况1
    自己配置上禁用ssl了
  • 情况2
    控制机器和被控制机器插件、或jmeter版本不一致.
Connection refused to host: 192.168.3.156; nested exception is: 
    java.net.ConnectException: Connection refused: connect

奴隶机器启动防火墙了-关闭就好了

non-JRMP server at remote endpoint

端口被占用了 windows netstat -ano | findstr "1099"

error during JRMP connection establishment; nested exception is: 
    javax.net.ssl.SSLHandshakeException: PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed

生成的SSL文件不一致

Found ApacheJMeter_core.jar 


Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is:
        java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)
An error occurred: Listen failed on port: 0; nested exception is:
        java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)
errorlevel=1

需要配置环境变量 %JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;

Exception creating connection to: 192.168.3.156; nested exception is: 
    java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)

Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is:
        java.io.IOException: java.security.UnrecoverableKeyException: Cannot recover key
An error occurred: Listen failed on port: 0; nested exception is:
        java.io.IOException: java.security.UnrecoverableKeyException: Cannot recover key
errorlevel=1
Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is:
        java.io.IOException: Keystore was tampered with, or password was incorrect
An error occurred: Listen failed on port: 0; nested exception is:
        java.io.IOException: Keystore was tampered with, or password was incorrect
errorlevel=1

python websocket 压力测试

import websocket
import time
import threading

SERVER_URL = "ws://192.168.3.51:9501/"
def on_message(ws, message):
    print(message)


def on_error(ws, error):
    print(error)


def on_close(ws):
    print("### closed ###")


def on_open(ws):

    def send_trhead():
        send_info = 'PING'
    while True:
        time.sleep(5)
        ws.send('PING')


    t = threading.Thread(target=send_trhead)
    t.start()




def on_start(a):
    time.sleep(a%20)
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp(SERVER_URL + str(a),
                on_message=on_message,
                on_error=on_error,
                on_close=on_close)
    ws.on_open = on_open
    ws.run_forever()




from threadpool import ThreadPool, makeRequests
if __name__ == "__main__":
    #init_logging()
    pool = ThreadPool(20000)
    test = list()
    for ir in range(20000):
        test.append(ir)
    requests = makeRequests(on_start, test)
    [pool.putRequest(req) for req in requests]
    pool.wait()

相关资料

高并发websocket客户端测试代码
pip安装加速

WebSocket进行压力测试
jmeter分布式压测—-windows
ServerAgent-2.2.3
Jmeter分布式压测和监控实践

JMeter安装

Jmeter 安装 (win10 下)
Jmeter的下载安装和环境变量配置(Windows10系统)

JMeter分布式部署

Jmeter分布式的坑
Jmeter分布式测试的各种坑之jmeter-server修改ip
JMeter 4使用SSL密钥库在云中进行远程测试 已创建rmi_keystore.jks,请将其master复制到slave的bin目录中。之后你可以重启jmeter-server.bat奴隶
基于JMeter进行分布式测试
传输机制将使用SSL
server.rmi.ssl.disable=true

es-docker

FROM php:7.2

# Version
ENV PHPREDIS_VERSION 4.0.1
ENV SWOOLE_VERSION 4.4.4
ENV EASYSWOOLE_VERSION 3.x-dev

# Timezone
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo 'Asia/Shanghai' > /etc/timezone

# Libs
RUN apt-get update \
    && apt-get install -y \
    curl \
    wget \
    git \
    zip \
    libz-dev \
    libssl-dev \
    libnghttp2-dev \
    libpcre3-dev \
    && apt-get clean \
    && apt-get autoremove -y

# Composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/local/bin/composer \
    && composer self-update --clean-backups

# PDO extension
RUN docker-php-ext-install pdo_mysql

# Bcmath extension
RUN docker-php-ext-install bcmath

# Redis extension
RUN wget http://pecl.php.net/get/redis-${PHPREDIS_VERSION}.tgz -O /tmp/redis.tar.tgz \
    && pecl install /tmp/redis.tar.tgz \
    && rm -rf /tmp/redis.tar.tgz \
    && docker-php-ext-enable redis

# Swoole extension
RUN wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz \
    && mkdir -p swoole \
    && tar -xf swoole.tar.gz -C swoole --strip-components=1 \
    && rm swoole.tar.gz \
    && ( \
    cd swoole \
    && phpize \
    && ./configure --enable-async-redis --enable-mysqlnd --enable-openssl --enable-http2 \
    && make -j$(nproc) \
    && make install \
    ) \
    && rm -r swoole \
    && docker-php-ext-enable swoole


# 部署node-agent
ADD swoole-tracker-vx.y.z.tar.gz /tmp/
RUN cp /tmp/86d89a960330704760/swoole_tracker72.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/ && \
    cd /tmp/86d89a960330704760 && \
    ./deploy_env.sh 192.168.56.102 && \
    rm -rf /tmp/86d89a960330704760

# 添加entrypoint脚本
RUN printf '#!/bin/sh\n/opt/swoole/script/php/swoole_php /opt/swoole/node-agent/src/node.php &\nphp $@' > /opt/swoole/entrypoint.sh && \
    chmod 755 /opt/swoole/entrypoint.sh

# 启用entrypoint脚本(-x方便调试, 可以去掉)
# ENTRYPOINT [ "sh", "-x", "/opt/swoole/entrypoint.sh" ]

RUN printf 'extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/swoole_tracker72.so\n' > /usr/local/etc/php/conf.d/swoole-tracker.ini


WORKDIR /var/www/code



# Install easyswoole
RUN cd /var/www/code \
    && composer require easyswoole/easyswoole=${EASYSWOOLE_VERSION} \
    && php vendor/bin/easyswoole install

EXPOSE 9501

ENTRYPOINT ["php", "/var/www/code/easyswoole", "start"]
FROM centos:centos7

#version defined
ENV SWOOLE_VERSION 4.4.4
ENV EASYSWOOLE_VERSION 3.x-dev

#update core
RUN yum update -y

#install libs
RUN yum install -y curl zip unzip  wget openssl-devel gcc-c++ make autoconf

#install php
RUN yum install -y epel-release
RUN rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
RUN yum clean all
RUN yum update -y
RUN yum install -y php71w-devel php71w-openssl php71w-gd php71w-mbstring php71w-mysqli

# composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/bin/composer \
    && composer self-update --clean-backups

# use aliyun composer
RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# swoole ext
RUN wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz \
    && mkdir -p swoole \
    && tar -xf swoole.tar.gz -C swoole --strip-components=1 \
    && rm swoole.tar.gz \
    && ( \
    cd swoole \
    && phpize \
    && ./configure --enable-openssl \
    && make \
    && make install \
    ) \
    && sed -i "2i extension=swoole.so" /etc/php.ini \
    && rm -r swoole

# Dir
WORKDIR /easyswoole

# install easyswoole

RUN cd /easyswoole \
    && composer require easyswoole/easyswoole=${EASYSWOOLE_VERSION} \
    && php vendor/bin/easyswoole install


# 部署node-agent
ADD swoole-tracker-vx.y.z.tar.gz /tmp/
RUN cp /tmp/86d89a960330704760/swoole_tracker71.so /usr/lib64/php/modules/ && \
    cd /tmp/86d89a960330704760 && \
    ./deploy_env.sh 192.168.56.102 && \
    rm -rf /tmp/86d89a960330704760

# 添加entrypoint脚本
RUN printf '#!/bin/sh\n/opt/swoole/script/php/swoole_php /opt/swoole/node-agent/src/node.php &\nphp-fpm $@' > /opt/swoole/entrypoint.sh && \
    chmod 755 /opt/swoole/entrypoint.sh

# 启用entrypoint脚本(-x方便调试, 可以去掉)
ENTRYPOINT [ "sh", "-x", "/opt/swoole/entrypoint.sh" ]

RUN printf 'extension=/usr/lib64/php/modules/swoole_tracker71.so\n' > /etc/php.d/swoole-tracker.ini


EXPOSE 9501

Loaded plugins: fastestmirror

yum update 报错 Loaded plugins: fastestmirror

  1. vi /etc/yum/pluginconf.d/fastestmirror.conf # 由enabled = 1修改为enabled = 0 意思是禁用它
  2. vi /etc/yum.conf # 修改为plugins=0 不使用插件
  3. vi /etc/sysconfig/network-scripts/ifcfg-ens33 # ifcfg-ens33 可能不是这个名字 找前缀为 ifcfg-ens [将ONBOOT改为yes, wq!保存退出]
  4. service network restart # 重新启动网络

相关资料

安装时出现Loaded plugins: fastestmirror解决办法

easyswoole中的mysqli带条件返回数据及总条数

easyswoole mysqli 分页

正确用法

<?php
$table_name = 'xsk_test';
$page=3;
$page_size=20;
$db->where('status', 1);
$db->withTotalCount();
$data = $db->get($table_name,[($page-1)*$page_size,$page_size],'*');
$count = $db->getTotalCount();

错误用法

<?php
$table_name = 'xsk_test';
$page=3;
$page_size=20;
$db->where('status', 1);
$data = $db->get($table_name,[($page-1)*$page_size,$page_size],'*');
$count = $db->count();// 这儿的count的where条件会消失

mysqli的源码

count是再次调用了get的方法 源码位置

    /**
     * 聚合-计算总数
     * @param string $tableName 表名称
     * @param string|null $filedName 字段名称
     * @return mixed
     * @throws ConnectFail
     * @throws PrepareQueryFail
     */
    public function count($tableName, $filedName = null)
    {
        if (is_null($filedName)) {
            $filedName = '*';
        }
        $isFetch = $this->isFetchSql;
        $retval = $this->get($tableName, null, "COUNT({$filedName}) as retval");
        if ($isFetch || $retval instanceof Mysqli) {
            return $retval;
        }
        return $retval ? $retval[0]['retval'] : false;
    }

相关资料

官方文档

计算机中的存储单位

计算机中的存储单位 单位转换

最小、最大单位是什么

最小单位 位(bit)-8位二进制数称为一个字节(byte)

位(bit)是二进制数的最基本单位, 也是存储器存储信息的最小单位,8位二进制数称为一个字节(byte). 当一个数作为一个整体存入或取出时, 这个数叫做存储字. 存储字可以是一个字节, 也可以是若干个字节. 若干个忆记单元组成一个存储单元, 大量的存储单元的集合组成一个存储体(MemoryBank).

  • 常见最大单位 1TB (Trillionbyte 万亿字节 太字节)
  • 已知最大单位 1BB (Brontobyte 一千亿亿亿字节)= 1024 YB.

高位字节、低位字节

计算机的数值应视为连续若干个二进制位的集合, 所谓高、低字节就是此集合中位地址高/低的二进制位集合

一般一个16位(双字节)的数据,比如 FF1A (16进制)
那么高位字节就是FF,低位是1A

如果是32位的数据,比如 3F68415B
高位字(不是字节)是3F68
低位字是415B

右边是低位位,左边是高位

单位之间怎么换算

1B(Byte 字节)=8bit,
1KB (Kilobyte 千字节)=1024B,
1MB (Megabyte 兆字节 简称“兆”)=1024KB,
1GB (Gigabyte 吉字节 又称“千兆”)=1024MB,
1TB (Trillionbyte 万亿字节 太字节)=1024GB,其中1024=2^10 ( 2 的10次方),
1PB(Petabyte 千万亿字节 拍字节)=1024TB,
1EB(Exabyte 百亿亿字节 艾字节)=1024PB,
1ZB (Zettabyte 十万亿亿字节 泽字节)= 1024 EB,
1YB (Yottabyte 一亿亿亿字节 尧字节)= 1024 ZB,
1BB (Brontobyte 一千亿亿亿字节)= 1024 YB.

注:“兆”为百万级数量单位。
附:进制单位全称及译音
yotta, [尧]它, Y. 10^21,
zetta, [泽]它, Z. 10^18,
exa, [艾]可萨, E. 10^15,
peta, [拍]它, P. 10^12,
tera, [太]拉, T. 10^9,
giga, [级]咖, G. 10^6,
mega, [兆],M. 10^3

硬盘容量缩水

计算机中采用二进制,这样就造成在操作系统中对容量的计算是以每1024为一进制的
而硬盘厂商在计算容量时,则是以每1000为一进制的,每1000“字节”为1KB

相关资料

存储单位
计算机存储单位
高位字节、低位字节

php-单元测试

easyswoole 单元测试 php单元测试

安装

composer require easyswoole/phpunit Tip: 自3.2.5版本的Easyswoole起,已经默认集成了 easyswoole/phpunit 组件

目录结构

|--App
|--|--|
.....
|--Tests
|--|--Api
|--|--|--IndexTests.php
|--|--Models
|--|--|--UserTests.php

IndexTests.php API接口测试

<?php


namespace Tests\Api;
use PHPUnit\Framework\TestCase;
use App\HttpController\Index;
use EasySwoole\HttpClient\HttpClient;

class IndexTests extends TestCase
{
    protected $baseUrl = 'http://ip地址:9501';

    public function testIndex()
    {
        $url = $this->baseUrl . '/user/login'; 
        $client = new HttpClient($url);


        $username = 'zhangshan';
        $password = 'qwe12345';
        $deviceId = 1;

        $client->setQuery(['username' => $username, 'password' => $password, 'device_type' => $deviceId]);

        $response = $client->get();

        $body = $this->parsingJson($response->getBody());

        if ($response->getBody()) {
            var_dump($body);
        } else {
            echo 'Error: ' . $response->getErrCode() . ': ' . $response->getErrMsg() . "\n";
        }

        $this->assertTrue(true);//断言结果是否为true,如果不为true则报错
        $this->assertEquals('hello world', $response->response);//断言结果是否等于hello world,如果不等于则报错
    }
    /**
     * 解析json数据
     *
     * @param string $jsonStr
     * @return object
     */
    protected function parsingJson($jsonStr)
    {
        // $body = json_decode($jsonStr);
        return json_decode($jsonStr);
    }
}

UserTests.php 数据模型测试

<?php
namespace Tests\Models;
use PHPUnit\Framework\TestCase;
use App\Models\AccountModel;

class UserTests extends TestCase
{
    public function testInfo()
    {
        $uid = 13;
        $accountModel = new AccountModel();
        $data=  $accountModel->info($uid);
        // var_dump($data); 8
        $this->assertEquals(8, $data['robot_id']);//断言返回的id为1
    }
}

相关资料

phpunit-单元测试神器
Easyswoole/Phpunit

Jmeter-websocket测试

Jmeter-websocket测试

链接:https://pan.baidu.com/s/1ylM48hwaqk-xtsQR0rTv-w
提取码:rqfn

插件管理

  1. https://jmeter-plugins.org/install/Install/
  2. plugins-manager.jar 下载好的文件放到lib/ext目录下

websocket插件下载

WebSocket Samplers by Peter Doornbosch

相关资料

Jmeter插件下载地址
Jmeter:websocket测试
Jmeter进行webSocket接口测试
Jmeter对Web Socket进行压力测试
jmeter5.1在windows(含插件安装)及linux环境下安装