One strategy I've seen is to allocate blocks of IDs at a time. When you connect, grab the "next ID", increment by ten, and then those ten IDs are yours to use in that connection. Go back for more when they're exhausted.

Update: Since you already have a table of next IDs (each row is an ID, independent of the other rows), you could have multiple rows that you go to. Say you make 20 such rows, each with a different ID in it to start. Each process can go to one of those rows, get the ID, and then increment by 20. You can choose a row at random or according to your process ID or something.

Both of these strategies winds up allocating IDs out of order. Also, they basically "put off" the scaling problem by a fixed factor. If you have more than 20 clients, they'll start waiting on each other.

If you want to be able to scale indefinitely, you have to generate your ID some way. Since you have 64 bit integers, maybe you could generate them the old fashioned way. Start with time and $$ (see perlvar) and mix in a per-process serial number.

use English; # Assumes 16-bit PID and 32-bit time my $unique_number = ($serial_number++ << (16+32)) + (time << 16) + $PID;

In reply to Re: [OT] Persistent Object IDs by kyle
in thread [OT] Persistent Object IDs by TedYoung

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.