-
-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utilize MarshalJSON and UnmarshalJSON interface implementations #503
Comments
Update on the performance implications of the workaround above. Note: These tests are from my laptop in France to a hosted server in Germany. The raw values might not reflect on-server performance, but the relative values demonstrates the performance problem. existing behaviour, which strips out the decimal values t0 := time.Now()
err = rethinkdb.Table(name).Insert(candles[:100]).Exec(session)
d := time.Since(t0)
log.WithField("duration", d.Seconds()).Info("test") time to insert 100 records is 0.23339381 seconds using above work around t0 := time.Now()
for _, candle := range candles[:100] {
if err = json.NewEncoder(b).Encode(candle); err != nil {
return err
}
if err = rethinkdb.Table(name).Insert(rethinkdb.JSON(b.String())).Exec(session); err != nil {
return err
}
b.Reset()
}
d := time.Since(t0)
log.WithField("duration", d.Seconds()).Info("test") time to insert 100 records is 5.65757508 seconds batching the encoding I also tried the following b := new(bytes.Buffer)
bufs := make([]string, 100)
for i, task := range tasks[:100] {
if err = json.NewEncoder(b).Encode(task); err != nil {
return err
}
bufs[i] = b.String()
b.Reset()
}
t0 := time.Now()
err = rethinkdb.Table(name).Insert(bufs[:100]).Exec(session)
d := time.Since(t0)
log.WithField("duration", d.Seconds()).Info("test") to see if the slow down was in the encoding, or the rethinkdb-go actions. Interestingly, no documents were created in the RethinkDB database yet no error was given. |
Came up with another workaround: create a separate struct just for inserting and retrieving objects into RethinkDB. Basically, a copy of the original struct with each |
Is your feature request related to a problem? Please describe.
Custom types can sometimes produce empty values in a RethinkDB document. I have implemented my own decimal type:
It implements both
json.Marshaler
andjson.Unmarshaler
. This type encodes and decodes without issue using the standardencoding/json
package. So I was surprised to see the following document stored in RethinkDBwhen using
What I would expect to see is
Describe the solution you'd like
If this library could use the
json.Marshaler
andjson.Unmarshaler
implementations, I would get the expected value by just usingDescribe alternatives you've considered
My workaround comes from this issue and is basically:
This is not only more verbose but also creates separate calls to Insert instead of sending a batch which impacts performance and also eliminates the transaction-like quality of sending a slice of objects to Insert.
Additional context
Is there something about RethinkDB or this library that would prevent adding this functionality? I would be happy to give it a try but not if someone has already proven it is a bad idea.
The text was updated successfully, but these errors were encountered: