当前位置: 首页 > wzjs >正文

wordpress 微媒体插件济南网站seo优化

wordpress 微媒体插件,济南网站seo优化,asp网站打开,网站源码分享网实现了 go多协程压力测试实现了Monitor,异步统计qps、时延、cpu(client端)等指标,周期printStat。只需要把单条执行func传给Monitor即可命令行传参ctrlc之后正常退出(mock cpu 占用) 代码见 https://gitee.com/bbjg001/golearning/tree/master/others/…

实现了

  • go多协程压力测试
  • 实现了Monitor,异步统计qps、时延、cpu(client端)等指标,周期printStat。只需要把单条执行func传给Monitor即可
  • 命令行传参
  • ctrl+c之后正常退出
  • (mock cpu 占用)

代码见 https://gitee.com/bbjg001/golearning/tree/master/others/stress_monitor

执行

go run *.go -action w -routine 5 -duration 30s

效果

在这里插入图片描述

更多的

可以把收集到的指标转给/metrics接口,可以实现外部手机指标,提供给prometheus收集,接口grafana实现可视化监控展示

util.go

package mainimport ("context""fmt""math/rand""os""sync/atomic""time""github.com/rcrowley/go-metrics""github.com/shirou/gopsutil/v3/process"
)type SCMonitor struct {registry       metrics.Registryinterval       time.DurationstopChan       chan struct{}qpsCounter     metrics.CounterlatencyTimer   metrics.TimertotalRequests  uint64failedRequests uint64lastCompute    time.Time
}func NewSCMonitor(interval time.Duration) *SCMonitor {registry := metrics.NewRegistry()return &SCMonitor{registry:     registry,interval:     interval,stopChan:     make(chan struct{}),qpsCounter:   metrics.NewCounter(),latencyTimer: metrics.NewTimer(),}
}func (m *SCMonitor) Start() {// 注册指标m.registry.Register("requests.qps", m.qpsCounter)m.registry.Register("requests.latency", m.latencyTimer)// CPU监控cpuGauge := metrics.NewGauge()m.registry.Register("system.cpu", cpuGauge)m.lastCompute = time.Now()go func() {p, err := process.NewProcess(int32(os.Getpid()))if err != nil {fmt.Printf("Failed to init process monitor: %v\n", err)return}ticker := time.NewTicker(m.interval)defer ticker.Stop()// fmt.Printf("time\tqps\tcpu\tlatency999\tlatency99\tlatency9\tlatencyMean\n")fmt.Printf("%-12s%-30s%-10s%-16s%-16s%-16s%-16s\n","time", "qps", "cpu", "latency999", "latency99", "latency9", "latencyMean")for {select {case <-m.stopChan:returncase <-ticker.C:// 更新CPU指标if percent, err := p.Percent(0); err == nil {cpuGauge.Update(int64(percent * 100))}// 打印周期报告m.PrintReport()}}}()
}func (m *SCMonitor) Monitor(ctx context.Context, work func() (duration time.Duration, succeed bool)) {for {select {case <-ctx.Done():returndefault:duration, succeed := work()m.RecordRequest(duration, succeed)}}
}func (m *SCMonitor) RecordRequest(latency time.Duration, succeed bool) {atomic.AddUint64(&m.totalRequests, 1)if !succeed {atomic.AddUint64(&m.failedRequests, 1)}m.qpsCounter.Inc(1)m.latencyTimer.Update(latency)
}func (m *SCMonitor) PrintReport() {now := time.Now().Format("15:04:05")// fmt.Printf("\n=== Metrics Report @ %s ===\n", now)fmt.Printf("%-12s", now)// QPS计算if qps := m.registry.Get("requests.qps"); qps != nil {counter := qps.(metrics.Counter)interval := time.Since(m.lastCompute).Milliseconds()rate := float64(counter.Count()*1000) / float64(interval)qpsStr := fmt.Sprintf("%.1f (Total: %d)", rate, atomic.LoadUint64(&m.totalRequests))fmt.Printf("%-30s", qpsStr)counter.Clear()}m.lastCompute = time.Now()// CPU使用率if cpu := m.registry.Get("system.cpu"); cpu != nil {cpuStr := fmt.Sprintf("%.1f%%\t", float64(cpu.(metrics.Gauge).Value())/100)fmt.Printf("%-10s", cpuStr)}// 时延统计if timer := m.registry.Get("requests.latency"); timer != nil {t := timer.(metrics.Timer)fmt.Printf("%-16.2f%-16.2f%-16.2f%-16.2f\n", t.Percentile(0.999)/1000000, t.Percentile(0.99)/1000000,t.Percentile(0.9)/1000000, t.Mean()/1000000)}
}func (m *SCMonitor) Stop() {close(m.stopChan)m.PrintReport() // 最终报告
}// 模拟cpu负载
func mockCpuLoad(loadPercentage int, durationSecond int) {workTime := time.Duration(loadPercentage) * time.MillisecondsleepTime := time.Duration(100-loadPercentage) * time.Millisecondctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(durationSecond))defer cancel()for {select {case <-ctx.Done():returndefault:start := time.Now()// 在工作时间内进行计算for time.Since(start) < workTime {// 执行一些计算密集型操作_ = rand.Intn(1000) * rand.Intn(1000)}time.Sleep(sleepTime)}}
}

main.go

package mainimport ("context""flag""fmt""math/rand""os""os/signal""syscall""time"
)var (testCfg = TConfig{}values  = make([]string, 1000)baseVal string
)type TConfig struct {routine  intaction   stringduration time.Duration
}func (c TConfig) String() string {return "=============测试参数\n" +fmt.Sprintf("routine: %d\n", c.routine) +fmt.Sprintf("action: %s\n", c.action) +fmt.Sprintf("duration: %v\n", c.duration)
}func init() {parseFlags()
}func parseFlags() {flag.IntVar(&testCfg.routine, "routine", 1, "线程数")flag.StringVar(&testCfg.action, "action", "r", "action, w|r")flag.DurationVar(&testCfg.duration, "duration", time.Minute, "测试时长")flag.Parse()
}func doWrite(uid int64) (time.Duration, bool) {// 此处uit只做传参示例d := int(rand.Float64() * 10000)startTime := time.Now()time.Sleep(time.Microsecond * time.Duration(d))succeed := rand.Float64() < 0.002return time.Since(startTime), succeed
}func doRead(uid int64) (time.Duration, bool) {d := int(rand.Float64() * 5000)startTime := time.Now()time.Sleep(time.Microsecond * time.Duration(d))succeed := rand.Float64() < 0.0001return time.Since(startTime), succeed
}func main() {fmt.Println(testCfg.String())fmt.Println("可Ctrl+C退出")go mockCpuLoad(15, 12) // 模拟cpu负载start := time.Now()ctx, cancel := context.WithTimeout(context.Background(), testCfg.duration)defer cancel()signalCh := make(chan os.Signal, 1)signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM)monitor := NewSCMonitor(3 * time.Second)monitor.Start()defer monitor.Stop()for i := 0; i < testCfg.routine; i++ {if testCfg.action == "w" {go monitor.Monitor(ctx, func() (duration time.Duration, succeed bool) { // 只需要传入一个控制测试停止的Context和M一个单条条执行的func即可,其他的的交给Monitorreturn doWrite(int64(i))})} else if testCfg.action == "r" {go monitor.Monitor(ctx, func() (duration time.Duration, succeed bool) {return doRead(int64(i))})} else {panic(fmt.Sprintf("unsupport param action: %s", testCfg.action))}}select {case <-ctx.Done():fmt.Println("测试完成, 正在退出 ...")breakcase <-signalCh: // 收到退出信号,正常处理退出testCfg.duration = time.Since(start)fmt.Println("收到终止信号, 正在退出 ...")cancel()break}fmt.Println(testCfg.String())
}

文章转载自:

http://6easjHiw.trLhc.cn
http://zMc0B3vl.trLhc.cn
http://XnW5w2mZ.trLhc.cn
http://a4nYGiBD.trLhc.cn
http://8IhkVr87.trLhc.cn
http://YY4IqzAz.trLhc.cn
http://p6Z1JcVt.trLhc.cn
http://OUsnSkmI.trLhc.cn
http://o57r7tM5.trLhc.cn
http://40t2wtDE.trLhc.cn
http://5tYWbqXe.trLhc.cn
http://JuHoR2S5.trLhc.cn
http://6SERiMwN.trLhc.cn
http://JhSuMknC.trLhc.cn
http://V2LFj0n6.trLhc.cn
http://LrhecqgV.trLhc.cn
http://wYoQvmHT.trLhc.cn
http://rkYlJ83o.trLhc.cn
http://8ZQtogJj.trLhc.cn
http://GrXHyTlx.trLhc.cn
http://FATAULdK.trLhc.cn
http://3VaSLI7p.trLhc.cn
http://5PB546t5.trLhc.cn
http://QwC0IAJ7.trLhc.cn
http://b9AJtyN7.trLhc.cn
http://EdYzLg24.trLhc.cn
http://ndhUpPAc.trLhc.cn
http://SFxeatB5.trLhc.cn
http://hoV9ZBby.trLhc.cn
http://kx6nDc83.trLhc.cn
http://www.dtcms.com/wzjs/754512.html

相关文章:

  • 做网站和做软件哪个赚钱哪几个做内贸的网站比较好一点
  • 深圳网站开发一薇dede手机网站更新
  • 湖北襄阳网站建设怎么做链接网站
  • 盗qq的钓鱼网站怎么做如何创建商业网站
  • 乐趣公园 wordpress宁波企业网站排名优化公司
  • 自己做网站需要买哪些东西国家企业信用信息公示系统官网山东
  • 在合肥做网站前端月薪大概多少钱外贸网站推广外包
  • 在线购物的网站制作网站的论文怎么写
  • 汽车租赁网站设计mvc5网站开发之美电子版
  • 网站 设计案例最新新闻热点话题
  • 模块化网站开发网站建设对企业重要性
  • 武威市建设局网站 放管服网站部署
  • 江苏新有建设集团有限公司官方网站宝贝做网站
  • 本地做那种网站好一些营销团队网站建设
  • 学校网站系统破解版wordpress顶踩插件
  • 做数据新闻的网站有哪些企业名录2022版
  • 大数据网站开发工程师怎样做网站卖自己的产品教程
  • 备案ip 查询网站查询网站查询企业取名
  • 音乐网站设计规划书网业小说畅读服务
  • 手机网站建设策划方案做产品表情的网站
  • 昆明建设局网站号码免费网站建设朋友交流
  • 中国建设劳动学会是假网站吗wordpress媒体库图片太多
  • 平台如何制作网站创意交易平台网
  • 十大那种直播软件衡阳企业seo优化首选
  • 网站制作预付款会计分录简单企业网站用什么
  • 网上写作最好的网站神马收录提交入口
  • 响应式网站排版app小程序怎么开发
  • 长沙做网站的包吃包住4000微芒科技网站建设top
  • 网站百度收录查询湖北网站推广策略
  • gps建站步骤有没有代做毕业设计的网站