美文网首页
Spring boot 2.x Undertow Redis m

Spring boot 2.x Undertow Redis m

作者: 大继 | 来源:发表于2020-03-20 20:33 被阅读0次

环境描述

当前时间全部使用最新稳定版本。
测试环境为 Mac book pro 2018 16G
Jmeter 测试环境为 cpu intel v3 24G win10

使用Mac book pro 做为服务器,Redis 跑在docker 上面,mysql 也在Mac book pro 上面运行。

小米千兆路由,wifi 5G(双频),7类千兆网线(比起一般网线性能提升10~20%)

预备条件

冷热数据都弄32+W 条

for...

配置
server:
  port: 8080
  undertow:
    io-threads: 8   #默认cpu个数,执行非柱塞任务,例如监听器。
    worker-threads: 800  
实体类采用真实类Shelf,依赖3~4个表有One2One ,One2May
@Entity
@Table(name = "shelf"
        ,indexes = {@Index(columnList = "subject,subjectId",unique = true)}
)
//@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@NamedEntityGraph(name = "shelf.all", attributeNodes =
        {@NamedAttributeNode("shelfItems"),@NamedAttributeNode("shelfPromotions"),@NamedAttributeNode("shelfDetail")})
public class Shelf  implements Serializable {

    @Id
    @Column(length = 37)
    private String id;

    @ApiModelProperty("名称")
    @Column
    private String name;

    @ApiModelProperty("概要")
    @Column
    private String summary;

    @Column(length = 767)
    private String image;


    @OneToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    @JoinColumn(foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private ShelfDetail shelfDetail;

    /**
     * 逻辑上是交付方式
     */
    @ApiModelProperty("上架主体:例如 商品,付费的文章,徽章领取")
    @Column(length = 32)
    private String subject;

    @ApiModelProperty("上架主体Id:例如 商品id,付费的文章id,徽章类型,简书")
    @Column(length = 37)
    private String subjectId;


    @ApiModelProperty("单价,无item时使用,有item时显示最小单价,模仿淘宝")
    @Column
    private Double price;

    @ApiModelProperty("原价")
    @Column
    private Double originalPrice;


    /**
     * 使用 double 的原因,例如超市,散件货使用kg来表达,更加灵活。
     */
    @ApiModelProperty("库存,如果有item 为item 总数")
    @Column
    private Double quantity = 0.0;

    @ApiModelProperty("上架")
    @Column
    private Boolean up;

    @ApiModelProperty("置顶")
    @Column
    private Boolean top;

    /**
     * 供应商信息、现在业务还不要
     */


    @ApiModelProperty("促销")
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "shelfId",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Set<ShelfPromotion> shelfPromotions;


    @ApiModelProperty("属性细分类")
    @OneToMany(fetch= FetchType.LAZY,orphanRemoval = true,cascade = CascadeType.ALL)
    @JoinColumn(name = "shelfId",foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Set<ShelfItem> shelfItems;

    @ApiModelProperty("最小价格:如果存在item 显示")
    @Column
    private Double minPrice = 0.0;

    @ApiModelProperty("最稿价格:如果存在item 显示")
    @Column
    private Double maxPrice = 0.0;

    @ApiModelProperty("最小原价价格:如果存在item 显示")
    @Column
    private Double originalMinPrice = 0.0;

    @ApiModelProperty("最大原价价格:如果存在item 显示")
    @Column
    private Double originalMaxPrice = 0.0;

    /**
     * 发起人,操作这个实体的人
     */
    @ApiModelProperty("发起人id")
    @Column
    private Long userId;

    @ApiModelProperty("标记")
    @Column
    private String remark;

    @Column
    private Date updateTime;

    @Column
    private Date createTime;
}

一,单机测试

其他均为默认。

1,静态文件测试

1.1 第一次需要启动线程,比较慢

ab -n 5000 -c 150 http://localhost:8080/redis/shelves

Concurrency Level:      150
Time taken for tests:   0.951 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      695000 bytes
HTML transferred:       25000 bytes
Requests per second:    5256.83 [#/sec] (mean)
Time per request:       28.534 [ms] (mean)
Time per request:       0.190 [ms] (mean, across all concurrent requests)
Transfer rate:          713.57 [Kbytes/sec] received

静态文件测试第二次测试结果

Concurrency Level:      150
Time taken for tests:   0.664 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      695000 bytes
HTML transferred:       25000 bytes
Requests per second:    7532.65 [#/sec] (mean)
Time per request:       19.913 [ms] (mean)
Time per request:       0.133 [ms] (mean, across all concurrent requests)
Transfer rate:          1022.50 [Kbytes/sec] received

静态文件测试第三次测试结果,距离上次就几秒的时间
看到系统内核 kernel_task(os 系统级链接NIO,和ab可能都依赖这个内核需要双机测试来证实) cpu上到 160%


image.png

ab 命令阻塞,估计是内核selelct 处理不过来

1.2 mysql 单条数据(注这个鬼,mysql 也会启动缓存)

由于随机脚本比较难搞先忽略 ,以首次读取为例, 性能在估计1200/sec 那样

ab -n 4000 -c 100 http://localhost:8080/shelves/1001

Concurrency Level:      100
Time taken for tests:   1.959 seconds
Complete requests:      4000
Failed requests:        0
Total transferred:      2108000 bytes
HTML transferred:       1620000 bytes
Requests per second:    2041.44 [#/sec] (mean)
Time per request:       48.985 [ms] (mean)
Time per request:       0.490 [ms] (mean, across all concurrent requests)
Transfer rate:          1050.62 [Kbytes/sec] received
1.3 mysql 下单测试

记忆中的性能: 800+ /s

1.4 Redis 单挑插入,单线程

大概在 1111 /s +-

完成查询时间:2020年3月20日 上午12:23:11
完成一万条:2020年3月20日 上午12:23:20
完成查询时间:2020年3月20日 上午12:23:20
完成一万条:2020年3月20日 上午12:23:30
完成查询时间:2020年3月20日 上午12:23:30
完成一万条:2020年3月20日 上午12:23:38
完成查询时间:2020年3月20日 上午12:23:38
完成一万条:2020年3月20日 上午12:23:47
完成查询时间:2020年3月20日 上午12:23:47
完成一万条:2020年3月20日 上午12:23:55
完成查询时间:2020年3月20日 上午12:23:55
完成一万条:2020年3月20日 上午12:24:03
完成查询时间:2020年3月20日 上午12:24:04
完成一万条:2020年3月20日 上午12:24:12
...
1.5 Redis 配合spring mvc 写入

ab -n 6000 -c 150 http://localhost:8080/redis/strings/random

Concurrency Level:      150
Time taken for tests:   1.653 seconds
Complete requests:      6000
Failed requests:        0
Total transferred:      804000 bytes
HTML transferred:       0 bytes
Requests per second:    3629.01 [#/sec] (mean)
Time per request:       41.334 [ms] (mean)
Time per request:       0.276 [ms] (mean, across all concurrent requests)
Transfer rate:          474.89 [Kbytes/sec] received

总结: 受限于http链接

1.6 Reids 多线程写入

30线程写入30W 数据,用时29/s
10344.82 / s

60线程写入 用时 26/S
100 线程 19/s. 15789.47/s
200 线程 也是19/s
补充:把线程池调高到200 200 线程写是25秒,前面都是100线程池
总结: 最高性能在 100 线程那样。

main完成查询时间:2020年3月20日 上午1:17:43
10000 Thread-12 开始  2020年3月20日 上午1:17:43
10000 Thread-4 开始  2020年3月20日 上午1:17:43
....
Thread-23 结束  2020年3月20日 上午1:18:12
Thread-7 结束  2020年3月20日 上午1:18:12
Thread-14 结束  2020年3月20日 上午1:18:12
Thread-3 结束  2020年3月20日 上午1:18:12
Thread-4 结束  2020年3月20日 上午1:18:12
执行完毕:2020年3月20日 上午1:18:12
1.7 redis 多线程读取

30W 数据随机读取

50 31/s
100 25/s
150 29/s
注:可能是我线程池的问题
线程池开到150 150线程 22s
200 200 21s

总结: 在线程充足的情况下,读的性能大概是写1.2倍那样
电脑老是睿频,全靠感觉了。

1.8 Redis 单个查询

ab -n 4000 -c 100 http://localhost:8080/redis/shelves/1001

  • 数据库有30W 和只有两条,,性能竟然相差无几。*
Concurrency Level:      100
Time taken for tests:   1.231 seconds
Complete requests:      4000
Failed requests:        0
Total transferred:      3208000 bytes
HTML transferred:       2720000 bytes
Requests per second:    3248.60 [#/sec] (mean)
Time per request:       30.782 [ms] (mean)
Time per request:       0.308 [ms] (mean, across all concurrent requests)
Transfer rate:          2544.31 [Kbytes/sec] received
1.9 Redis Watch 单条数据操作,加上 100ms 失败重试 5次。

性能可怜的低下.
ab -n 3000 -c 100 http://localhost:8080/redis/shelves/1001/order/callback

Concurrency Level:      100
Time taken for tests:   22.761 seconds
Complete requests:      3000
Failed requests:        0
Total transferred:      1635000 bytes
HTML transferred:       1269000 bytes
Requests per second:    131.80 [#/sec] (mean)
Time per request:       758.714 [ms] (mean)
Time per request:       7.587 [ms] (mean, across all concurrent requests)
Transfer rate:          70.15 [Kbytes/sec] received

总结: key 越多使用watch 性能越高, 单数据大并发非常不适合。

相关文章

网友评论

      本文标题:Spring boot 2.x Undertow Redis m

      本文链接:https://www.haomeiwen.com/subject/dzyryhtx.html