测试了一下caddy

By root at 2017-12-10 07:23 • 949次点击
root

测试了一下caddy代理goyoubbs .速度飞快,有空再详测


caddy


用你的方式也测一下ssldocker,感觉它们使用的原理和工具是相同的。

ego008 at 2017-12-10 08:43
1

@ego008 嗯 元旦放三天,到时候在一起慢慢折腾 goyoubbs没有使用mysql 我想随机插入几百万的数据,然后再AB 对nginx caddy ssldocker来个系统负载测试,网页响应测试等等。

root at 2017-12-10 10:22
2

@ego008

有什么办法可以随机插入几百万的测试数据呢?

root at 2017-12-10 13:00
3

@root 这个没法了,有空给你写几段代码试试

ego008 at 2017-12-10 14:17
4

package main

import (
	"encoding/json"
	"flag"
	"github.com/ego008/youdb"
	"github.com/rs/xid"
	"log"
	"math/rand"
	"os"
	"strconv"
	"time"
)

var (
	dbFile      = "mytestdata.db"
	userNum     = 100000
	categoryNum = 10000
	articleNum  = 1000000
)

type (
	Article struct {
		Id           uint64 `json:"id"`
		Uid          uint64 `json:"uid"`
		Cid          uint64 `json:"cid"`
		RUid         uint64 `json:"ruid"`
		Title        string `json:"title"`
		Content      string `json:"content"`
		ClientIp     string `json:"clientip"`
		Tags         string `json:"tags"`
		AddTime      uint64 `json:"addtime"`
		EditTime     uint64 `json:"edittime"`
		Comments     uint64 `json:"comments"`
		CloseComment bool   `json:"closecomment"`
		Hidden       bool   `json:"hidden"`
	}
	Category struct {
		Id       uint64 `json:"id"`
		Name     string `json:"name"`
		Articles uint64 `json:"articles"`
		About    string `json:"about"`
		Hidden   bool   `json:"hidden"`
	}
	User struct {
		Id            uint64 `json:"id"`
		Name          string `json:"name"`
		Gender        string `json:"gender"`
		Flag          int    `json:"flag"`
		Avatar        string `json:"avatar"`
		Password      string `json:"password"`
		Email         string `json:"email"`
		Url           string `json:"url"`
		Articles      uint64 `json:"articles"`
		Replies       uint64 `json:"replies"`
		RegTime       uint64 `json:"regtime"`
		LastPostTime  uint64 `json:"lastposttime"`
		LastReplyTime uint64 `json:"lastreplytime"`
		LastLoginTime uint64 `json:"lastlogintime"`
		About         string `json:"about"`
		Notice        string `json:"notice"`
		NoticeNum     int    `json:"noticenum"`
		Hidden        bool   `json:"hidden"`
		Session       string `json:"session"`
	}
)

func main() {
	dFile := flag.String("f", "mytestdata.db", "db file path")
	aNum := flag.Int("a", 1000000, "want to add article num")
	flag.Parse()

	articleNum = *aNum
	dbFile = *dFile

	if _, err := os.Stat(dbFile); err == nil {
		err = os.Remove(dbFile)
		if err != nil {
			log.Fatalf("Remove db file Error: %v", err)
		}
	}

	db, err := youdb.Open(dbFile)
	if err != nil {
		log.Fatalf("Connect db Error: %v", err)
	}

	log.Println("user num:", userNum)
	log.Println("cate num:", categoryNum)
	log.Println("arti num:", articleNum)

	t1 := time.Now()

	// User
	log.Println("insert User")
	for i := 1; i <= userNum; i++ {
		flag := 5
		if i < 5 {
			flag = 99
		}
		timeStamp := uint64(time.Now().Unix())
		obj := User{
			Id:            uint64(i),
			Name:          "user" + strconv.FormatInt(int64(i), 10),
			Avatar:        "0",
			Password:      "21232f297a57a5a743894a0e4a801fc3",
			Flag:          flag,
			RegTime:       timeStamp,
			LastLoginTime: timeStamp,
		}
		jb, _ := json.Marshal(obj)
		db.Hset("user", youdb.I2b(obj.Id), jb)
		db.Hset("user_name2uid", []byte(obj.Name), youdb.I2b(obj.Id))
		db.Hset("user_flag:"+strconv.Itoa(flag), youdb.I2b(obj.Id), []byte(""))

		if i%(userNum/10) == 0 {
			log.Println("---i", i, "/", userNum)
		}
	}
	db.HsetSequence("user", uint64(userNum))

	// Category
	log.Println("insert Category")
	for i := 1; i <= categoryNum; i++ {
		obj := Category{
			Id:   uint64(i),
			Name: "category" + strconv.FormatInt(int64(i), 10),
		}
		jb, _ := json.Marshal(obj)
		db.Hset("category", youdb.I2b(obj.Id), jb)

		if i%(categoryNum/10) == 0 {
			log.Println("---i", i, "/", categoryNum)
		}
	}
	db.HsetSequence("category", uint64(categoryNum))

	// Article
	log.Println("insert Article")
	for i := 1; i <= articleNum; i++ {
		var currentUser User
		//
		randUid := random(1, userNum)
		rs := db.Hget("user", youdb.I2b(uint64(randUid)))
		if rs.State == "ok" {
			err := json.Unmarshal(rs.Data[0], &currentUser)
			if err != nil {
				log.Println(err)
				continue
			}
		} else {
			continue
		}
		randCid := random(1, categoryNum)
		title := xid.New().String()
		timeStamp := uint64(time.Now().Unix())
		obj := Article{
			Id:       uint64(i),
			Uid:      currentUser.Id,
			Cid:      uint64(randCid),
			Title:    title,
			Content:  "Content" + title,
			AddTime:  timeStamp,
			EditTime: timeStamp,
		}

		jb, _ := json.Marshal(obj)
		aidB := youdb.I2b(obj.Id)
		db.Hset("article", aidB, jb)
		// 总文章列表
		db.Zset("article_timeline", aidB, obj.EditTime)
		// 分类文章列表
		db.Zset("category_article_timeline:"+strconv.FormatUint(obj.Cid, 10), aidB, obj.EditTime)
		// 用户文章列表
		db.Hset("user_article_timeline:"+strconv.FormatUint(obj.Uid, 10), youdb.I2b(obj.Id), []byte(""))
		// 分类下文章数
		db.Zincr("category_article_num", youdb.I2b(obj.Cid), 1)

		currentUser.LastPostTime = timeStamp
		currentUser.Articles++

		jb, _ = json.Marshal(currentUser)
		db.Hset("user", youdb.I2b(obj.Uid), jb)

		if i%(articleNum/100) == 0 {
			log.Println("---i", i, "/", articleNum)
		}
	}
	db.HsetSequence("article", uint64(articleNum))

	db.Close()
	log.Println("db close")

	log.Println("well done, time", time.Now().Sub(t1))
}

func random(min, max int) int {
	rand.Seed(time.Now().Unix())
	return rand.Intn(max-min) + min
}

已编译好的可实行文件: insertyoudb_linux_amd64 https://pan.baidu.com/s/1mi7U6hy 5

10万用户、1万分类,100万帖子
费时 time 33m37.106093961s
数据插入逻辑跟生产环境相同,平均 520贴/秒

ego008 at 2017-12-10 15:53
5

ok 元旦在三个平台测试一下

root at 2017-12-10 17:05
6

坐等详谈啊,都可以运行了,为什么还要这个呢,还有这个东西怎么配置?网上说得很简单,但是好像不能开机启动

xinNONOY at 2018-01-01 13:55
7

性能对比,在这里已经有了,可以自己看看
https://www.golangnote.com/topic/216.html 24

root at 2018-01-01 20:43
8

我跑这段代码估计要跑70小时,,,,,....

小强 at 2018-04-12 01:24
9

@小强

这也太久了,什么配置的服务器?

ego008 at 2018-04-12 13:55
10

azure 4cpu 32g内存

理论上不差啊

我还没跑完,,

就翻车了.

小强 at 2018-04-12 17:52
11
登录 后发表评论