When you install the Ubuntu system on a physical machine, don’t forget to do these things to improve your computer’s performance.
My experiments found that the improvement was very noticeable, based on Ubuntu 20.10 and my hardware.
Use s-tui to monitor and test your max CPU frequency

How to install
sudo apt install python3-pip stress
python3 -m pip install --user s-tui
How to use
sudo s-tui
You can use the arrow keys and space bar to switch between Monitor mode and Stress mode. The Stress mode performs a stress test on the CPU.
Use indicator-cpufreq to set your CPU frequency

How to install
sudo apt install indicator-cpufreq
sudo reboot
How to use
Look at the status bar icon in the upper right corner and click on the emerging icon to set the CPU’s performance mode.
Read More
Why migrate to qmgo
- Mgo is a convenient library for golang to operate mongodb, but it does not support the latest features of mongodb, such as Transaction.
- My old project is written in mgo. If I want to migrate to the official mongo-driver, its syntax is more primitive, the usage difference is large, and the migration cost will be higher.
- I found a library called qmgo, which is based on the official mongo-driver package, but it is closer to mgo in terms of syntax and suitable for simple and rude migrations.
Below I will record the methods used in the migration process, which I found out by myself. If you have any questions, please correct me.
Batch replacement
- Batch replace
github.com/globalsign/mgo/bson with go.mongodb.org/mongo-driver/bson
- Batch replace
bson.NewObjectId() with primitive.NewObjectID()
- Batch replace
bson.ObjectId with primitive.ObjectID
- Batch replace
.Find(bson.M with .Find(c, bson.M
- Batch replace
.Find(search to .Find(c, search
- Batch replace
.Insert( to .InsertOne(c,
- Batch replace
.Update( to .UpdateOne(c,
- Batch replace
.RemoveAll( to .RemoveAll(c,
- Batch replace
.Remove( to .Remove(c,
- Batch replace
errors.Is(err, mgo.ErrNotFound) with qmgo.IsErrNoDocuments(err)
- Batch replace
.EnsureIndex(mgo.Index{ for
.CreateOneIndex(c, options.IndexModel{
Note: qmgo/options.IndexModel uses Key (and optional IndexOptions), not Keys/Options from the official mongo-driver mongo.IndexModel.
Copy and paste
- Where there is no context, copy and paste everywhere
c := context.Background()
- If it is in the interface method of gin, you can directly use gin’s
c *gin.Context (but if multi-coroutine operation needs to Copy gin’s Context)
Function substitution
- Replace the bson.IsObjectIdHex() method:
package db
import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
func IsObjectIDHex(hex string) bool {
_, err := primitive.ObjectIDFromHex(hex)
if err != nil {
return false
}
return true
}
- Replace the bson.ObjectIdHex() method:
package db
import (
"fmt"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func ObjectIDHex(hex string) primitive.ObjectID {
id, err := primitive.ObjectIDFromHex(hex)
if err != nil {
panic(fmt.Sprintf("Invalid input to ObjectIDHex: %+v", hex))
}
return id
}
These functions can be placed in the package of the auxiliary method or the package of the database operation, and then replace the references in batches.
Summary
At this point, the project completed the migration within two hours and started running smoothly.
Thanks to the author of qmgo for making the wheels for me.
If I have the opportunity, I will also open up some wheels.
Read More