1
0
mirror of https://shylinux.com/x/icebergs synced 2025-05-03 20:07:01 +08:00
This commit is contained in:
harveyshao 2021-12-22 10:30:25 +08:00
parent 5a60718d64
commit 05340dee07
8 changed files with 49 additions and 68 deletions

View File

@ -14,15 +14,15 @@ import (
"shylinux.com/x/toolkits/util/bench"
)
func _bench_http(m *ice.Message, name, target string, arg ...string) {
func _bench_http(m *ice.Message, target string, arg ...string) {
nconn := kit.Int64(kit.Select("10", m.Option(NCONN)))
nreqs := kit.Int64(kit.Select("1000", m.Option(NREQS)))
m.Echo("nconn: %d nreqs: %d\n", nconn, nreqs*nconn)
nreqs := kit.Int64(kit.Select("100", m.Option(NREQS)))
m.Echo("nconn: %d total: %d\n", nconn, nreqs*nconn)
list := []*http.Request{}
for _, v := range strings.Split(target, ice.SP) {
for _, v := range strings.Split(target, ice.NL) {
switch ls := kit.Split(v); ls[0] {
case http.MethodPost:
case http.MethodPost: // POST,url,file
if f, e := os.Open(ls[2]); m.Assert(e) {
defer f.Close()
@ -35,6 +35,7 @@ func _bench_http(m *ice.Message, name, target string, arg ...string) {
m.Assert(err)
list = append(list, req)
}
m.Debug("what %v", v)
}
var body int64
@ -48,7 +49,7 @@ func _bench_http(m *ice.Message, name, target string, arg ...string) {
m.Echo("body: %d\n", body)
m.ProcessInner()
}
func _bench_redis(m *ice.Message, name, target string, arg ...string) {
func _bench_redis(m *ice.Message, target string, arg ...string) {
}
const (
@ -67,17 +68,14 @@ func init() {
kit.MDB_SHORT, kit.MDB_ZONE, kit.MDB_FIELD, "time,id,type,name,text,nconn,nreqs",
)},
}, Commands: map[string]*ice.Command{
"/bench": {Name: "/bench cmd...", Help: "性能压测", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy(m.Optionv("cmd"))
}},
BENCH: {Name: "bench zone id auto insert", Help: "性能压测", Action: ice.MergeAction(map[string]*ice.Action{
mdb.INSERT: {Name: "insert zone=some type=http,redis name=demo text nconn=3 nreqs=10", Help: "添加"},
mdb.INSERT: {Name: "insert zone=some type=http,redis name=demo text='http://localhost:9020' nconn=3 nreqs=10", Help: "添加"},
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
switch m.Option(kit.MDB_TYPE) {
case HTTP:
_bench_http(m, m.Option(kit.MDB_NAME), m.Option(kit.MDB_TEXT))
_bench_http(m, m.Option(kit.MDB_TEXT))
case REDIS:
_bench_redis(m, m.Option(kit.MDB_NAME), m.Option(kit.MDB_TEXT))
_bench_redis(m, m.Option(kit.MDB_TEXT))
}
}},
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

@ -20,20 +20,18 @@ func _pack_write(o io.Writer, arg ...string) {
}
fmt.Fprintln(o)
}
func _pack_file(m *ice.Message, file string) string {
list := ""
func _pack_file(m *ice.Message, name, file string) string {
text := ""
if f, e := os.Open(file); e == nil {
defer f.Close()
if b, e := ioutil.ReadAll(f); e == nil {
list = fmt.Sprintf("%v", b)
if b, e := ioutil.ReadAll(f); e == nil && len(b) > 0 {
if list := strings.ReplaceAll(fmt.Sprintf("%v", b), ice.SP, ice.FS); len(list) > 0 {
text = list[1 : len(list)-1]
}
}
}
if list = strings.ReplaceAll(list, ice.SP, ","); len(list) > 0 {
return fmt.Sprintf(`[]byte{%v}`, list[1:len(list)-1])
}
return "[]byte{}"
return fmt.Sprintf(" \"%s\": []byte{%s},\n", name, text)
}
func _pack_dir(m *ice.Message, pack *os.File, dir string) {
m.Option(nfs.DIR_DEEP, ice.TRUE)
@ -49,8 +47,7 @@ func _pack_dir(m *ice.Message, pack *os.File, dir string) {
return
}
pack.WriteString(fmt.Sprintf(" \"%s\": %s,\n",
path.Join(dir, value[kit.MDB_PATH]), _pack_file(m, path.Join(dir, value[kit.MDB_PATH]))))
pack.WriteString(_pack_file(m, path.Join(dir, value[kit.MDB_PATH]), path.Join(dir, value[kit.MDB_PATH])))
})
pack.WriteString(ice.NL)
}
@ -61,12 +58,11 @@ func _pack_volcanos(m *ice.Message, pack *os.File, dir string) {
m.Option(nfs.DIR_ROOT, dir)
for _, k := range []string{ice.FAVICON, ice.PROTO_JS, ice.FRAME_JS} {
pack.WriteString(fmt.Sprintf(" \"/%s\": %s,\n", k, _pack_file(m, path.Join(dir, k))))
pack.WriteString(_pack_file(m, ice.PS+k, path.Join(dir, k)))
}
for _, k := range []string{"lib", "page", "panel", "plugin"} {
m.Cmd(nfs.DIR, k).Sort(kit.MDB_PATH).Table(func(index int, value map[string]string, head []string) {
pack.WriteString(fmt.Sprintf(" \"/%s\": %s,\n",
value[kit.MDB_PATH], _pack_file(m, path.Join(dir, value[kit.MDB_PATH]))))
pack.WriteString(_pack_file(m, ice.PS+value[kit.MDB_PATH], path.Join(dir, value[kit.MDB_PATH])))
})
}
pack.WriteString(ice.NL)

View File

@ -70,7 +70,7 @@ func init() {
m.Log_EXPORT(cli.SOURCE, main, cli.TARGET, file)
m.Cmdy(nfs.DIR, file, "time,path,size,link,action")
m.Cmdy(PUBLISH, mdb.CREATE, ice.BIN_ICE_SH)
m.Cmdy(PUBLISH, ice.CONTEXTS, ice.BASE)
m.Cmdy(PUBLISH, ice.CONTEXTS, ice.CORE)
m.StatusTimeCount()
}},
}})

View File

@ -35,17 +35,16 @@ func init() {
if p := r.URL.Path; strings.HasPrefix(p, "/debug") {
r.URL.Path = strings.Replace(r.URL.Path, "/debug", "/code", -1)
m.Debug("rewrite %v -> %v", p, r.URL.Path)
return true
}
return false
})
}},
"/pprof/": {Name: "/pprof/", Help: "性能分析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.R.URL.Path = strings.Replace("/code"+m.R.URL.Path, "code", "debug", 1)
m.R.URL.Path = strings.Replace(kit.Path("/code/"+cmd, arg...), "/code", "/debug", -1)
http.DefaultServeMux.ServeHTTP(m.W, m.R)
m.Render(ice.RENDER_VOID)
}},
PPROF: {Name: "pprof zone id auto create", Help: "性能分析", Action: ice.MergeAction(map[string]*ice.Action{
PPROF: {Name: "pprof zone id auto", Help: "性能分析", Action: ice.MergeAction(map[string]*ice.Action{
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case BINNARY:
@ -56,20 +55,16 @@ func init() {
})
}
}},
mdb.CREATE: {Name: "create zone=some binnary service seconds=3", Help: "创建"},
mdb.INSERT: {Name: "insert zone type name text", Help: "插入"},
mdb.CREATE: {Name: "create zone=some binnary=bin/ice.bin service='http://localhost:9020/debug/pprof/profile' seconds=3", Help: "创建"},
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option(SERVICE), SECONDS, m.Option(SECONDS))
cmd := kit.Simple(m.Confv(PPROF, kit.Keym(PPROF)), "-text", m.Option(BINNARY), msg.Append(kit.MDB_FILE))
res := strings.Split(m.Cmdx(cli.SYSTEM, cmd), ice.NL)
if len(res) > 20 {
res = res[:20]
}
cmd := kit.Simple(m.Configv(PPROF), "-text", m.Option(BINNARY), msg.Append(nfs.FILE))
res := kit.Slice(strings.Split(m.Cmdx(cli.SYSTEM, cmd), ice.NL), 0, 20)
m.Cmd(mdb.INSERT, PPROF, "", mdb.ZONE, m.Option(kit.MDB_ZONE),
kit.MDB_TEXT, strings.Join(res, ice.NL), kit.MDB_FILE, msg.Append(kit.MDB_FILE))
kit.MDB_TEXT, strings.Join(res, ice.NL), nfs.FILE, msg.Append(nfs.FILE))
m.Echo(strings.Join(res, ice.NL))
m.ProcessInner()
}},
@ -77,7 +72,7 @@ func init() {
u := kit.ParseURL(m.Option(ice.MSG_USERWEB))
p := u.Hostname() + ":" + m.Cmdx(tcp.PORT, aaa.RIGHT)
m.Cmd(cli.DAEMON, m.Confv(PPROF, kit.Keym(PPROF)), "-http="+p, m.Option(BINNARY), m.Option(kit.MDB_FILE))
m.Cmd(cli.DAEMON, m.Configv(PPROF), "-http="+p, m.Option(BINNARY), m.Option(nfs.FILE))
m.Echo("http://%s/ui/top", p)
m.ProcessInner()
}},
@ -85,11 +80,12 @@ func init() {
m.Fields(len(arg), "time,zone,count,binnary,service,seconds", m.Config(kit.MDB_FIELD))
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
m.PushAction(ice.RUN, mdb.REMOVE)
m.Action(mdb.CREATE)
return
}
m.Table(func(index int, value map[string]string, head []string) {
m.PushDownload(kit.MDB_LINK, "pprof.pd.gz", value[kit.MDB_FILE])
m.PushDownload(kit.MDB_LINK, "pprof.pd.gz", value[nfs.FILE])
m.PushButton(web.SERVE)
})
}},

View File

@ -102,7 +102,7 @@ echo "hello world"
m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(u.Host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ":"), 1)))
if len(arg) == 0 {
arg = append(arg, "misc", "core", "base", "binary", "source", "project")
arg = append(arg, "misc", "core", "base", "project", "binary", "source")
}
for _, k := range arg {
if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) {
@ -159,25 +159,22 @@ echo "hello world"
}
var _contexts = kit.Dict(
"project", `# 创建项目
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp project
`,
"source", `# 下载源码
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp source
`,
"binary", `# 安装应用
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp binary
`,
"base", `# 生产环境
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp app
"project", `# 创建项目
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp project
`,
"core", `# 开发环境
"base", `# 开发环境
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp dev
`,
"core", `# 生产环境
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp app
`,
"misc", `# 终端环境
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp
`,
"tool", `# 群组环境
export ctx_dev={{.Option "httphost"}} ctx_share={{.Option "share"}} ctx_river={{.Option "sess.river"}} ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp app
`,
)

View File

@ -71,27 +71,17 @@ func init() {
PLAN: {Name: "plan scale=week,day,week,month,year,long begin_time@date place@province auto insert export import", Help: "计划", Meta: kit.Dict(
ice.Display("/plugin/local/team/plan.js"),
), Action: ice.MergeAction(map[string]*ice.Action{
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case m.Conf(TASK, kit.Keym(kit.MDB_SHORT)):
m.Cmdy(mdb.INPUTS, m.Prefix(TASK), "", mdb.HASH, arg)
default:
m.Cmdy(mdb.INPUTS, m.Prefix(TASK), "", mdb.ZONE, m.Option(m.Conf(TASK, kit.Keym(kit.MDB_SHORT))), arg)
}
}},
mdb.PLUGIN: {Name: "plugin extra.ctx extra.cmd extra.arg", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
_task_modify(m, arg[0], arg[1], arg[2:]...)
}},
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
m.Option(ice.POD, m.Option("task.pod"))
m.Option("task.pod", "")
if m.PodCmd(m.PrefixKey(), ice.RUN, arg) {
return
}
msg := m.Cmd(TASK, arg[0], arg[1])
if pod := msg.Append(kit.KeyExtra(ice.POD)); pod != "" {
m.Option(ice.POD, pod)
}
m.Debug(msg.FormatMeta())
args := kit.Simple(kit.Keys(msg.Append(kit.KeyExtra(ice.CTX)), msg.Append(kit.KeyExtra(ice.CMD))), arg[2:])
if !m.PodCmd(args) {
m.Cmdy(args)
}
m.Cmdy(kit.Simple(kit.Keys(msg.Append(kit.KeyExtra(ice.CTX)), msg.Append(kit.KeyExtra(ice.CMD))), arg[2:]))
}},
}, TASK), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
begin_time, end_time := _plan_scope(m, 8, arg...)

View File

@ -183,6 +183,7 @@ const (
ADD = "add"
OPT = "opt"
PRO = "pro"
PIE = "pie"
TAGS = "tags"
DIFF = "diff"
@ -259,9 +260,12 @@ func init() {
}
}
}},
PIE: {Name: "pie", Help: "饼图", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(TOTAL, PIE)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
m.Action(PULL, MAKE, PUSH, TAGS)
m.Action(PULL, MAKE, PUSH, TAGS, PIE)
files, adds, dels, last := _status_list(m)
m.Status("files", files, "adds", adds, "dels", dels, "last", last.Format(ice.MOD_TIME))

View File

@ -26,7 +26,7 @@ func init() {
)},
}, Commands: map[string]*ice.Command{
TOTAL: {Name: "total name auto pie", Help: "统计量", Action: map[string]*ice.Action{
"pie": {Name: "pie", Help: "饼图", Hand: func(m *ice.Message, arg ...string) {
PIE: {Name: "pie", Help: "饼图", Hand: func(m *ice.Message, arg ...string) {
defer m.Display("/plugin/story/pie.js")
m.Cmd(TOTAL).Table(func(index int, value map[string]string, head []string) {
if value["name"] == "total" {