olbat[m] has quit [Quit: Client limit exceeded: 20000]
hightower2 has joined #crystal-lang
ur5us has joined #crystal-lang
Chillfox has quit [Ping timeout: 260 seconds]
<FromGitter>
<paulocoghi> Hello Crystal community! ⏎ ⏎ On `Time` api, is it possible to directly read the `Int64` for seconds from epoch and `Int32` for nanoseconds?
olbat[m] has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
<straight-shoota>
Not really. You can access the ivar as `time.@seconds` but that's not a public API.
<straight-shoota>
Time#nanosecond exposes the nanosecond component directly, though
<FromGitter>
<paulocoghi> My use case is to create unique timestamps which include nano seconds to avoid collision when creating millions of timestamps per second
<FromGitter>
<paulocoghi> They will be use in a database similar to couchdb/pouchdb where the timestamp allows offline insertions on different nodes, with collision-free synchronizations after the creation
^raz^ has quit [Quit: *fump*]
raz has joined #crystal-lang
raz has quit [Changing host]
raz has joined #crystal-lang
hightower2 has quit [Ping timeout: 256 seconds]
<yxhuvud>
birthday paradox means you have no guarantee of uniqueness though.
<FromGitter>
<paulocoghi> I will read about it right now! Thanks!
<yxhuvud>
or well, it wouldn't be good enough for uniqueness guarantee anyhow, but birthday paradox mean you will have duplicates *often*.
<FromGitter>
<paulocoghi> Now I understand what you mean. In my understanding, the statistical chance of collision when working with nanosecond resolution is only considerable when passing the 999 million insertions per second, which would be more than one insertion per nanosecond
<FromGitter>
<paulocoghi> But it seems that my thinking may be an ingenuous one xD
<FromGitter>
<Blacksmoke16> Wouldn't it be better to use UUIDs ⏎ ?
<FromGitter>
<christopherzimmerman> Yes, if he generated 1 billion records a second for a hundred years, with sufficient entropy he’d have a 50% chance of seeing a collision.
hightower2 has joined #crystal-lang
<FromGitter>
<paulocoghi> xD
<FromGitter>
<paulocoghi> Researching a bit, the fastest UUID library I could find by now is WUID (https://github.com/edwingeng/wuid), where it's possible to generate from 100M to 200M id's per second. Also, it's only capable of such speed because it's not fully UUID compliant (the fastest fully compliant library I found provides around 20M id's per second) ⏎ ⏎ If the first mentioned library is the world's fastest, using UUID
<FromGitter>
... would not help to ensure reliability over 1 billion records a second, since the approach is slower by itself than the desired threshold
<FromGitter>
<Blacksmoke16> do you really need over 1b records a second?
<FromGitter>
<paulocoghi> I do not need. Maybe a user of our database from the future xD xD
<FromGitter>
<paulocoghi> With the current constraints, I believe our database will not be able to surpass the 1M creations per second on the near future :)
ua_ has quit [Read error: Connection reset by peer]
ua_ has joined #crystal-lang
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
yxhuvud has joined #crystal-lang
Peter0x41 is now known as Peter0x44
<FromGitter>
<christopherzimmerman> Is your database going to be able to handle constant inserts of 1B records a second?
<FromGitter>
<christopherzimmerman> That seems like it's going to be a far more limiting factor than generating UUIDs.
notzmv has joined #crystal-lang
<FromGitter>
<paulocoghi> > Is your database going to be able to handle constant inserts of 1B records a second? ⏎ ⏎ No
<FromGitter>
<paulocoghi> > That seems like it's going to be a far more limiting factor than generating UUIDs. ⏎ ⏎ You are right
<riza>
@paulocoghi - I haven't yet seen a port of this to crystal, but the twitter snowflake ID generation system is a robust, scaleable, distributed ID generation system that you might find interesting. Quick google popped up a bunch of results, eg https://github.com/RobThree/IdGen
<riza>
we used a sql-native varient of snowflake at one company a few years back and it was both completely unnecessary and wonderfully capable
taskylizard has joined #crystal-lang
<FromGitter>
<paulocoghi> Thanks, @riza! IdGen is really interesting, timestamp-based *but* more solid than my idea :)
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
<riza>
in my memory the timestamp rolls over every millisecond, so each server generating IDs has 10+12 bits of entropy for every milli
<riza>
well, the 10 bits is usually some combination of fixed server_id and region identifier and such
<riza>
<timestamp in millis><server id><12 bit sequencial>, and the sequencial resets at every milli
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Changing host]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Changing host]
taskylizard has joined #crystal-lang
taskylizard has quit [Read error: Connection reset by peer]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
avane_ is now known as avane
taskylizard has quit [Changing host]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
<Guest95>
yeah, but in my case the JSON is part of the string I'm comparing
<FromGitter>
<Blacksmoke16> `" ".to_json != " "`
<FromGitter>
<Blacksmoke16> but `" ".to_json == %(" ")` and `" ".to_json == "\" \""`
<FromGitter>
<Blacksmoke16> so might just need to update the expected string to be the expected *json* string, not the json string's value i that makes sense
<FromGitter>
<Blacksmoke16> if that*
<Guest95>
so `operands` can contain a JSON string or something like "L00,#0a [FALSE] cbb1" so fixed it for now with `operands = JSON.parse(operands) rescue operands`
<Guest95>
thanks for the pointer!
<FromGitter>
<Blacksmoke16> mm that feels like a hack
<Guest95>
it is :D
<Guest95>
I can do it better, but for now I'm unblocked
<FromGitter>
<Blacksmoke16> 👍 fair enough
<Guest95>
it's possible to know if it's text or not