performace is poor, load 120MB, alloc 300MB memory #1226

Open
opened 2019-02-13 03:41:13 +00:00 by orange-jacky · 0 comments
orange-jacky commented 2019-02-13 03:41:13 +00:00 (Migrated from github.com)

go version go1.12beta2 darwin/amd64

code
`type (

IsmmgtDirectFlightDynamic struct {
	Id         int       `json:"id"`
	Accode     string    `json:"accode"`
	Org        string    `json:"org"`
	Dcity      string    `json:"dcity"`
	Dcountry   string    `json:"dcountry"`
	Dst        string    `json:"dst"`
	Acity      string    `json:"acity"`
	Acountry   string    `json:"acountry"`
	Week       string    `json:"week"`
	Enddate    time.Time `json:"enddate"`
	Startdate  time.Time `json:"startdate"`
	Note       string    `json:"note"`
	Aregion    string    `json:"aregion"`
	Dregion    string    `json:"dregion"`
	Hasstop    int       `json:"hasstop"`
	Stops      string    `json:"stops"`
	Isdomestic int       `json:"isdomestic"`
}

IsmmgtDirectFlight = IsmmgtDirectFlightDynamic //类型别名

IsmmgtDirectFlights struct {
	sli []*IsmmgtDirectFlight
}

)

func (m *IsmmgtDirectFlights) LoadFromDb() (num int, err error) {
mysql := MysqlIs()
engine := mysql.Engine
var sli []*IsmmgtDirectFlightDynamic
err = engine.Find(&sli)

num = len(sli)
if num > 0 { 
	m.sli = sli
}
return num, err

}`

go tool pprof
(pprof) peek Find Showing nodes accounting for 508.65MB, 100% of 508.65MB total ----------------------------------------------------------+------------- flat flat% sum% cum cum% calls calls% + context ----------------------------------------------------------+------------- 301.49MB 100% | aaa/xxx/util.(*IsmmgtDirectFlights).LoadFromDb 0 0% 0% 301.49MB 59.27% | github.com/go-xorm/xorm.(*Engine).Find 301.49MB 100% | github.com/go-xorm/xorm.(*Session).Find ----------------------------------------------------------+------------- 301.49MB 100% | github.com/go-xorm/xorm.(*Engine).Find 0 0% 0% 301.49MB 59.27% | github.com/go-xorm/xorm.(*Session).Find 301.49MB 100% | github.com/go-xorm/xorm.(*Session).find ----------------------------------------------------------+------------- 301.49MB 100% | github.com/go-xorm/xorm.(*Session).find 0 0% 0% 301.49MB 59.27% | github.com/go-xorm/xorm.(*Session).noCacheFind 298.89MB 99.14% | github.com/go-xorm/xorm.(*Session).rows2Beans 2.60MB 0.86% | github.com/go-xorm/xorm.(*Session).executeProcessors ----------------------------------------------------------+------------- 162.54MB 100% | github.com/go-xorm/xorm.(*Session).rows2Beans 0 0% 0% 162.54MB 31.96% | github.com/go-xorm/xorm.(*Session).noCacheFind.func1 162.54MB 100% | reflect.New ----------------------------------------------------------+------------- 2.60MB 100% | github.com/go-xorm/xorm.(*Session).rows2Beans.func1 0 0% 0% 2.60MB 0.51% | github.com/go-xorm/xorm.(*Session).noCacheFind.func2 2.60MB 100% | reflect.Append ----------------------------------------------------------+-------------

mysql table is 120MB, when use xorm load this table, it use 300MB, how to impove?

go version go1.12beta2 darwin/amd64 code `type ( IsmmgtDirectFlightDynamic struct { Id int `json:"id"` Accode string `json:"accode"` Org string `json:"org"` Dcity string `json:"dcity"` Dcountry string `json:"dcountry"` Dst string `json:"dst"` Acity string `json:"acity"` Acountry string `json:"acountry"` Week string `json:"week"` Enddate time.Time `json:"enddate"` Startdate time.Time `json:"startdate"` Note string `json:"note"` Aregion string `json:"aregion"` Dregion string `json:"dregion"` Hasstop int `json:"hasstop"` Stops string `json:"stops"` Isdomestic int `json:"isdomestic"` } IsmmgtDirectFlight = IsmmgtDirectFlightDynamic //类型别名 IsmmgtDirectFlights struct { sli []*IsmmgtDirectFlight } ) func (m *IsmmgtDirectFlights) LoadFromDb() (num int, err error) { mysql := MysqlIs() engine := mysql.Engine var sli []*IsmmgtDirectFlightDynamic err = engine.Find(&sli) num = len(sli) if num > 0 { m.sli = sli } return num, err }` go tool pprof `(pprof) peek Find Showing nodes accounting for 508.65MB, 100% of 508.65MB total ----------------------------------------------------------+------------- flat flat% sum% cum cum% calls calls% + context ----------------------------------------------------------+------------- 301.49MB 100% | aaa/xxx/util.(*IsmmgtDirectFlights).LoadFromDb 0 0% 0% 301.49MB 59.27% | github.com/go-xorm/xorm.(*Engine).Find 301.49MB 100% | github.com/go-xorm/xorm.(*Session).Find ----------------------------------------------------------+------------- 301.49MB 100% | github.com/go-xorm/xorm.(*Engine).Find 0 0% 0% 301.49MB 59.27% | github.com/go-xorm/xorm.(*Session).Find 301.49MB 100% | github.com/go-xorm/xorm.(*Session).find ----------------------------------------------------------+------------- 301.49MB 100% | github.com/go-xorm/xorm.(*Session).find 0 0% 0% 301.49MB 59.27% | github.com/go-xorm/xorm.(*Session).noCacheFind 298.89MB 99.14% | github.com/go-xorm/xorm.(*Session).rows2Beans 2.60MB 0.86% | github.com/go-xorm/xorm.(*Session).executeProcessors ----------------------------------------------------------+------------- 162.54MB 100% | github.com/go-xorm/xorm.(*Session).rows2Beans 0 0% 0% 162.54MB 31.96% | github.com/go-xorm/xorm.(*Session).noCacheFind.func1 162.54MB 100% | reflect.New ----------------------------------------------------------+------------- 2.60MB 100% | github.com/go-xorm/xorm.(*Session).rows2Beans.func1 0 0% 0% 2.60MB 0.51% | github.com/go-xorm/xorm.(*Session).noCacheFind.func2 2.60MB 100% | reflect.Append ----------------------------------------------------------+------------- ` mysql table is 120MB, when use xorm load this table, it use 300MB, how to impove?
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1226
No description provided.