You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Jens Alfke <je...@mooseyard.com> on 2011/06/26 23:25:50 UTC
Are server-generated doc IDs better?
If my client code has access to a ready supply of unique ID strings (in my case, Cocoa’s CFUUID API), is there any disadvantage to using those to create document IDs, versus using IDs generated by the server’s /_uuids endpoint?
On a similar note, if I’m talking to a server on localhost (from a mobile/desktop app) is there any reason not to use POST to create new documents? The warning in the docs seems to apply only if there are intermediate proxies that might repeat the request.
—Jens
Re: Are server-generated doc IDs better?
Posted by Randall Leeds <ra...@gmail.com>.
On Thu, Jun 30, 2011 at 00:35, Benoit Chesneau <bc...@gmail.com> wrote:
> On Thu, Jun 30, 2011 at 3:08 AM, Dale Harvey <da...@arandomurl.com> wrote:
>> CouchDB generates uuid's that attempts to minimise the amount of rebalancing
>> that needs to happen on insert, however thats only an optimization I would
>> worry about if you are under fairly severe load.
>>
>> If your application has natural id's then I would use them, if not then I
>> think its fine to use POST as long as you aware of the idempotent issue
>>
> Other way is to get a bunch of uuids from couch and using them in your
> PUT, so you don't have to generate yourself uuids. (and you have best
> of both world).
>
> - benoît
>
Benoitc is referring to GET /_uuids (optionally with ?count=X).
Re: Are server-generated doc IDs better?
Posted by Robert Newson <rn...@apache.org>.
You can fully randomized uuids by changing from 'sequential' to
'random' but, yes, the shared prefix is a compromise between random
uuids and values that play nicely with a b+tree.
B.
On 30 June 2011 20:04, Jens Alfke <je...@mooseyard.com> wrote:
>
> On Jun 30, 2011, at 12:35 AM, Benoit Chesneau wrote:
>
>> Other way is to get a bunch of uuids from couch and using them in your
>> PUT, so you don't have to generate yourself uuids. (and you have best
>> of both world).
>
> Yes, but it’s much simpler (and faster) to call CFUUIDCreate() rather than write all the code to manage a pool of available IDs, call the server on demand to fetch more, block if necessary until the server replies, handle HTTP errors…
>
>
>
> On Jun 29, 2011, at 6:08 PM, Dale Harvey wrote:
>
>> CouchDB generates uuid's that attempts to minimise the amount of rebalancing
>> that needs to happen on insert
>
> That’s funny — I had noticed yesterday that the doc IDs have long prefixes in common, and felt that this was possibly bad for performance because it slows down string comparisons (more bytes to scan before finding a difference.) But of course that’s trivial compared to the overhead you refer to of fetching more b-tree pages from disk on insert. This must indicate that I come from a hash-table background, not a b-tree one :)
>
> —Jens
Re: Are server-generated doc IDs better?
Posted by Jens Alfke <je...@mooseyard.com>.
On Jun 30, 2011, at 12:35 AM, Benoit Chesneau wrote:
> Other way is to get a bunch of uuids from couch and using them in your
> PUT, so you don't have to generate yourself uuids. (and you have best
> of both world).
Yes, but it’s much simpler (and faster) to call CFUUIDCreate() rather than write all the code to manage a pool of available IDs, call the server on demand to fetch more, block if necessary until the server replies, handle HTTP errors…
On Jun 29, 2011, at 6:08 PM, Dale Harvey wrote:
> CouchDB generates uuid's that attempts to minimise the amount of rebalancing
> that needs to happen on insert
That’s funny — I had noticed yesterday that the doc IDs have long prefixes in common, and felt that this was possibly bad for performance because it slows down string comparisons (more bytes to scan before finding a difference.) But of course that’s trivial compared to the overhead you refer to of fetching more b-tree pages from disk on insert. This must indicate that I come from a hash-table background, not a b-tree one :)
—Jens
Re: Are server-generated doc IDs better?
Posted by Benoit Chesneau <bc...@gmail.com>.
On Thu, Jun 30, 2011 at 3:08 AM, Dale Harvey <da...@arandomurl.com> wrote:
> CouchDB generates uuid's that attempts to minimise the amount of rebalancing
> that needs to happen on insert, however thats only an optimization I would
> worry about if you are under fairly severe load.
>
> If your application has natural id's then I would use them, if not then I
> think its fine to use POST as long as you aware of the idempotent issue
>
Other way is to get a bunch of uuids from couch and using them in your
PUT, so you don't have to generate yourself uuids. (and you have best
of both world).
- benoît
Re: Are server-generated doc IDs better?
Posted by Jason Smith <jh...@iriscouch.com>.
On Thu, Jun 30, 2011 at 8:08 AM, Dale Harvey <da...@arandomurl.com> wrote:
> I
> think its fine to use POST as long as you aware of the idempotent issue
IMHO:
PUT is more informative in client logs
PUT is more informative in server logs
PUT is harder to screw up, because you front-load the hard part:
getting some ids
And related:
Really, it is prudent never to oversell your hardware to Couch. It is
more, you might say "sustainable," to know that disk capacity and
bandwidth can support rebalancing (compacting) under typical or
worst-case loads. Among other benefits, it removes the leaky
abstraction where CouchDB seems to have an opinion about your doc ids.
--
Iris Couch
Re: Are server-generated doc IDs better?
Posted by Dale Harvey <da...@arandomurl.com>.
CouchDB generates uuid's that attempts to minimise the amount of rebalancing
that needs to happen on insert, however thats only an optimization I would
worry about if you are under fairly severe load.
If your application has natural id's then I would use them, if not then I
think its fine to use POST as long as you aware of the idempotent issue
Cheers
Dale
On 27 June 2011 18:44, Mark Hahn <ma...@boutiquing.com> wrote:
> I had to patch jquery.couch.js that comes with couch to use post. It
> was using a synchronous ajax call to get uuids which is a big no-no,
> especially since I am using the same code on node.
>
> On Sun, Jun 26, 2011 at 2:25 PM, Jens Alfke <je...@mooseyard.com> wrote:
> > If my client code has access to a ready supply of unique ID strings (in
> my case, Cocoa’s CFUUID API), is there any disadvantage to using those to
> create document IDs, versus using IDs generated by the server’s /_uuids
> endpoint?
> >
> > On a similar note, if I’m talking to a server on localhost (from a
> mobile/desktop app) is there any reason not to use POST to create new
> documents? The warning in the docs seems to apply only if there are
> intermediate proxies that might repeat the request.
> >
> > —Jens
>
>
>
> --
> Mark Hahn
> Website Manager
> mark@boutiquing.com
> 949-342-4246
>
Re: Are server-generated doc IDs better?
Posted by Mark Hahn <ma...@boutiquing.com>.
I had to patch jquery.couch.js that comes with couch to use post. It
was using a synchronous ajax call to get uuids which is a big no-no,
especially since I am using the same code on node.
On Sun, Jun 26, 2011 at 2:25 PM, Jens Alfke <je...@mooseyard.com> wrote:
> If my client code has access to a ready supply of unique ID strings (in my case, Cocoa’s CFUUID API), is there any disadvantage to using those to create document IDs, versus using IDs generated by the server’s /_uuids endpoint?
>
> On a similar note, if I’m talking to a server on localhost (from a mobile/desktop app) is there any reason not to use POST to create new documents? The warning in the docs seems to apply only if there are intermediate proxies that might repeat the request.
>
> —Jens
--
Mark Hahn
Website Manager
mark@boutiquing.com
949-342-4246