From 306e8d2f60c928aa77b226d487dce106d509733e Mon Sep 17 00:00:00 2001 From: shaoying Date: Mon, 21 Sep 2020 20:20:22 +0800 Subject: [PATCH] opt bench --- base/mdb/mdb.go | 2 +- base/tcp/tcp.go | 11 +++++++---- core/code/bench.go | 25 ------------------------- core/wiki/word.go | 1 - misc/alpha/alpha.go | 2 +- type.go | 5 +++-- 6 files changed, 12 insertions(+), 34 deletions(-) diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index 1ff93acb..fbbe2562 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -250,7 +250,7 @@ func _list_search(m *ice.Message, prefix, key, field, value string) { }) defer m.Cost("search") - task.Sync(list, func(task *task.Task, lock *task.Lock) error { + task.Wait(list, func(task *task.Task, lock *task.Lock) error { kit.CSV(kit.Format(task.Arg), 100000, func(index int, line map[string]string, head []string) { if line[field] != value { return diff --git a/base/tcp/tcp.go b/base/tcp/tcp.go index 01dd7233..5b101ad6 100644 --- a/base/tcp/tcp.go +++ b/base/tcp/tcp.go @@ -25,11 +25,14 @@ func _port_get(m *ice.Message, begin string) string { current = kit.Int(m.Conf(PORT, "meta.begin")) } for i := current; i < end; i++ { - if m.Cmd(cli.SYSTEM, "lsof", "-i", kit.Format(":%d", i)).Append(cli.CMD_CODE) != "0" { - m.Conf(PORT, "meta.current", i) - m.Log_SELECT(PORT, i) - return kit.Format("%d", i) + if c, e := net.Dial("tcp", kit.Format(":%d", i)); e == nil { + m.Info("port exists %v", i) + defer c.Close() + continue } + m.Conf(PORT, "meta.current", i) + m.Log_SELECT(PORT, i) + return kit.Format("%d", i) } return "" } diff --git a/core/code/bench.go b/core/code/bench.go index 674c52e9..8556b526 100644 --- a/core/code/bench.go +++ b/core/code/bench.go @@ -5,9 +5,7 @@ import ( "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/web" kit "github.com/shylinux/toolkits" - log "github.com/shylinux/toolkits/logs" "github.com/shylinux/toolkits/util/bench" - "github.com/shylinux/toolkits/util/bench/redis" "io" "io/ioutil" @@ -15,7 +13,6 @@ import ( "os" "strings" "sync/atomic" - "time" ) func _bench_list(m *ice.Message, zone string, id string, field ...interface{}) { @@ -53,15 +50,6 @@ func _bench_show(m *ice.Message, nconn, nreq int64, list []*http.Request) { m.Echo(s.Show()) m.Echo("body: %d\n", body) } -func _bench_redis(m *ice.Message, nconn, nreq int64, hosts []string, cmds []string) { - m.Log_CONF(NCONN, nconn, NREQS, nreq, "cmds", cmds, "hosts", hosts) - - s, e := redis.Redis(nconn, nreq, hosts, cmds, nil) - m.Assert(e) - - m.Echo("cmds: %s QPS: %.2f n/s AVG: %s time: %s \n", cmds, s.QPS, - log.FmtDuration(s.Cost/time.Duration(s.NReq)), log.FmtDuration(s.EndTime.Sub(s.BeginTime))) -} func _bench_engine(m *ice.Message, kind, name, target string, arg ...string) { for i := 0; i < len(arg); i += 2 { m.Option(arg[i], arg[i+1]) @@ -70,19 +58,6 @@ func _bench_engine(m *ice.Message, kind, name, target string, arg ...string) { nreqs := kit.Int64(kit.Select("1000", m.Option(NREQS))) m.Echo("nconn: %d nreqs: %d\n", nconn, nreqs*nconn) - if strings.HasPrefix(target, "redis://") { - hosts := []string{} - for _, v := range strings.Split(target, ",") { - hosts = append(hosts, strings.TrimPrefix(v, "redis://")) - } - - cmds := strings.Split(name, ",") - for _, cmd := range cmds { - _bench_redis(m, nconn, nreqs, hosts, []string{cmd}) - } - return - } - list := []*http.Request{} for _, v := range strings.Split(target, ",") { switch ls := kit.Split(v); ls[0] { diff --git a/core/wiki/word.go b/core/wiki/word.go index a2107822..39ad63c9 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -218,7 +218,6 @@ func _field_show(m *ice.Message, name, text string, arg ...string) { } } } - m.Debug("what %v", data) // 渲染引擎 m.Option("meta", data) diff --git a/misc/alpha/alpha.go b/misc/alpha/alpha.go index c1e48dc9..eec16909 100644 --- a/misc/alpha/alpha.go +++ b/misc/alpha/alpha.go @@ -47,7 +47,7 @@ func _alpha_find2(m *ice.Message, method, word string) { } var mu sync.Mutex - task.Sync(args, func(task *task.Task, lock *task.Lock) error { + task.Wait(args, func(task *task.Task, lock *task.Lock) error { info := task.Arg.(os.FileInfo) file := path.Join(p, info.Name()) kit.CSV(file, 100000, func(index int, value map[string]string, head []string) { diff --git a/type.go b/type.go index 8ab7eed8..a921592f 100644 --- a/type.go +++ b/type.go @@ -165,9 +165,10 @@ func (c *Context) _split(name string) []interface{} { case ":": switch kit.Value(item, kit.MDB_INPUT, ls[i+1]); ls[i+1] { case "textarea": - kit.Value(item, "style.width", "300") - kit.Value(item, "style.height", "150") + kit.Value(item, "style.width", "360") + kit.Value(item, "style.height", "120") case "button": + kit.Value(item, kit.MDB_VALUE, "") button = true } case "=":