Giter VIP home page Giter VIP logo

Comments (8)

khaf avatar khaf commented on June 13, 2024

Have you considered using an array and putting the objects in it? How big is your array?

g1 := map[interface{}]interface{}{1: "My first group"}
g2 := map[interface{}]interface{}{2: "My second group"}
g3 := map[interface{}]interface{}{3: "My third group"}

bin := NewBin("groups", []interface{}{g1, g2, g3})
client.PutBins(wpolicy, key, bin)

rec, _ := client.Get(policy, key)
fmt.Println(rec.Bins["groups"])

from aerospike-client-go.

EtienneBruines avatar EtienneBruines commented on June 13, 2024

Thank you for your response. I have considered using an array and putting the objects in it, but that defeats the whole purpose of using a database in this scenario. The actual scenario is more advanced than the basic scenario (Group also contains a parent/child relation with other Groups). This means it'd be desirable to be able to select the Group using its PK.

But if I understand correctly, the "best practice solution" would be to store the sequence as an array in a bin?

The arrays consist of max. 20 items.

from aerospike-client-go.

khaf avatar khaf commented on June 13, 2024

Unless I'm missing something, the best practice solution would be sorting in client-side. 20 Items do not represent a size or performance risk.

from aerospike-client-go.

cstivers78 avatar cstivers78 commented on June 13, 2024

The thing to keep in mind with regards to Aerospike is that it is a distributed hash table, where the keys are not ordered.

Sounds like you should have a record per Group. You can create a secondary index on the bin containing the parent Group's id, so you can perform queries on all children of a given parent. You can also have the inverse relationship in the parent, and do a Batch Read of the child Group ids. With a small dataset, meaning thousands or less, then sorting on the application side will be quite trivial.

from aerospike-client-go.

khaf avatar khaf commented on June 13, 2024

To expand on Chris's answer, in a distributed database, data may come from several different nodes. As a result, even if each data set from an individual node is sorted, another entity with access to the combined data streams from all nodes is needed to sort the merged data (complications ensue regarding space, ...)

In your case and with constraints you mentioned, the best candidate to do the sort ends up being in your own application.

from aerospike-client-go.

EtienneBruines avatar EtienneBruines commented on June 13, 2024

Thank you for the suggestion to do the sorting application side.
I decided to save the index in a bin (after one-time sorting), making it possible to read everything coming through via a channel, and put it in the correct index in an array. That way, when looking at the array, everything is sorted.
As for the child-elements, I am using a Query/Filter to search for the parent-key, and using the saved index for the sorting.

I wonder what the performance difference is between regular queries / scans versus saving those results in bins and fetching those specficially.
i.e.: would it be better to Query for "parent = 5", or would it be better to select "key 4, key 6, key 8"? Perhaps if using a batch, the latter would be faster..?

from aerospike-client-go.

EtienneBruines avatar EtienneBruines commented on June 13, 2024

I'm dropping the last question I asked ... I am curious, but I should stop worrying about performance this much. The average latency for reading a record is close to nothing (I wrote a golang Benchmark for the first time of my life - turns out, fetching the entire tree structure from the database costs about 1ms), so I shouldn't worry that much unless I'm doing massive reads per second.
Thank you very much for your answers.

from aerospike-client-go.

khaf avatar khaf commented on June 13, 2024

No worries, we are here to help.

The standard first and quick answer is: Do a quick and dirty benchmark.

That aside, there is certain overhead when you start expanding the number of keys in batch requests. In your use case with ~20 elements, I think the cost will be relatively negligible, but you may have to find another solution if that number increases.

You're still sending more than 20 * 20 bytes per request, not considering the headers. But don't rush to optimize, let it show up first in your profiling charts first.

from aerospike-client-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.