purplecity's recent timeline updates
purplecity

purplecity

V2EX member #403771, joined on 2019-04-21 23:26:15 +08:00
purplecity's recent replies
Jan 14, 2025
Replied to a topic by tjmxf 职场话题 程序员的职业发展路线
Jan 14, 2025
Replied to a topic by tjmxf 职场话题 程序员的职业发展路线
@sagaxu 我日了 说的没毛病。确实钻研的并不深入 也确实在中小公司并不需要 也确实没尝试过转啥管理岗 而且我们这一行只有 boss 在乎管理岗 真正一线基础开发岗经常 diss 管理岗菜的跟坨屎一样
Dec 2, 2024
Replied to a topic by hez2010 程序员 运行 100 万个异步并发任务需要多少内存
java 就是垃圾中的垃圾
Dec 2, 2024
Replied to a topic by northluo 酷工作 base 杭州, golang 服务端岗位简历
发了简历了 可能会很适合
Aug 17, 2019
Replied to a topic by purplecity 问与答 go 多个 goroutine 操作 mysql 出现数据混乱
@Maboroshii 在下面具体说明了下 数据来源是数据库的数据是每秒都会去查库的 不过确实数据库操作的结果没打日志
Aug 17, 2019
Replied to a topic by purplecity 问与答 go 多个 goroutine 操作 mysql 出现数据混乱
@keepeye 大佬代码在你下面一层。多谢
Aug 17, 2019
Replied to a topic by purplecity 问与答 go 多个 goroutine 操作 mysql 出现数据混乱
@hhyvs111 传的是变量没问题

for _,x := range tidList {
go func(m map[string]interface{}) {
//对 m 进行操作
}(x)
Aug 17, 2019
Replied to a topic by purplecity 问与答 go 多个 goroutine 操作 mysql 出现数据混乱
具体程序
```go
func init() {

_ = orm.RegisterDataBase("default", "mysql",
fmt.Sprintf("%s:%s@tcp(%s:%v)/%s?charset=utf8&allowNativePasswords=true",
CommonConf.MysqlUserName, CommonConf.MysqlPassWord, CommonConf.MysqlIP, CommonConf.MysqlPort, CommonConf.MysqlDefaultDatabase))
//注册模型
orm.RegisterModel(new(AdminUsers),new(Realtrade))
//自动创建表 参数二为是否 drop 然后创建表 参数三是否打印创建表过程
orm.RunSyncdb("default",false,true)
}

var hpOrm orm.Ormer

func getOrm() orm.Ormer {
if hpOrm == nil {
hpOrm = orm.NewOrm()
}
return hpOrm
}

func UpdateByCond(table string,cond,updateMap map[string]interface{}) {
o := getOrm()
qs := o.QueryTable(table)
for key,value := range cond {
qs = qs.Filter(key,value)
}
qs.Update(orm.Params(updateMap))
}

func GetOneRecord(table string,cond map[string]interface{},resultStruct interface{}) {
o := getOrm()
qs := o.QueryTable(table)
for key,value := range cond {
qs = qs.Filter(key,value)
}
qs.One(resultStruct)
}

func GetAllRecord(table string,cond map[string]interface{},resultStruct interface{}) {
o := getOrm()
qs := o.QueryTable(table)
for key,value := range cond {
qs = qs.Filter(key,value)
}
qs.All(resultStruct)
}
```
然后有个进程 A 每隔 1s 会去查库 查到了所需的 B 类型数据 有多少条就起多少个协程去用 UpdateByCond 和 GetOneRecord GetAllRecord 这些读取和更新操作。 模拟多个客户端我起了 200 个进程 这 200 个进程会在一分钟内每秒插入一条不同的 B 类型数据。所以 A 会每秒起 200 个 goroutine 去更新和读取操作。。。 比较挫。。用的是一个单利对象还没去看 beego orm 源码。。。 重复写和少写没更新都有。 别说 200 个进程了 10 个进程都会有出错。。
May 27, 2019
Replied to a topic by cod 程序员 Rust 和 go 哪个更有前途?
@wayslog 兄弟 就凭你这一句 我准备玩 rust
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2356 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 21ms · UTC 15:49 · PVG 23:49 · LAX 08:49 · JFK 11:49
♥ Do have faith in what you're doing.