Hi is there easy way to get a random bin key and value for a particular key than bringing all the bins ofthe records then processing it.
Can you clarify what you want to do?
Do you want to read a specific Bin? or Do you want to choose Bin at random and read it?
Select a bin at random and get its value.
Essentially you want to to do computation in the server to randomly choose a Bin and return its value. The best way to do this is using a record User Defined Function.
You will need to write the UDF in Lua, register it with the cluster and then it’s available to be invoked as many times as you like.
I hope that this helps
This can be implemented in several ways:
- write a UDF that conforms to the set of bins. Since you can list all the named bins, or know yourself the pattern of bins, you can generate a random number in Lua.
- do this at the client layer in the obvious ways - you can get the list of bins and randomly select one.
Aerospike does not have the native ability to randomly select a bin.
The reason I asked this question is due the performance impact of bringing all the data to client side is pretty high on client side is there a performance gain in the through using udf over bring data to client side?
Hi Critikal —
There’s a tradeoff, and without knowing the sizes in quesiton, it’s hard to make a recommendation.
In using a UDF, your database might be a little slower, because you’ll use more CPU on your server. If you’re limited by DB CPU, this would be a problem.
In bringing all the data back to the client, the network utilization will be higher and the client CPU will be higher - but the database CPU will be lower.
I hate to say, but there’s no free lunch. You might have to experiment with both cases and see what’s right for your application / deployment. We give you both capabilities, which is good for flexibility, but then you have to determine which to use.
For example, on Amazon, most instance have packet-per-second limits, so there might be a lot of spare CPU — using UDFs might be free. Or you might be using hybrid cloud with very high TPS, in which case the server CPU might be the issue.
We are working on supporting a faster & more native implementation of lists and maps, limiting the CPU exposure for common cases.