<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:20:17 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-9393] Very, very fast counters</title>
                <link>https://jira.mongodb.org/browse/SERVER-9393</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Fast Counters&lt;/p&gt;

&lt;p&gt;Scope&lt;/p&gt;

&lt;p&gt;To provide very fast counters and timers - making possible an increase in the volume and granularity of stats accumulated within the server.&lt;/p&gt;

&lt;p&gt;Not in scope&lt;/p&gt;

&lt;p&gt;DTrace integration is not part of this project.  Non-x86 processors will not be supported.&lt;/p&gt;

&lt;p&gt;Design&lt;/p&gt;

&lt;p&gt;Each counter consists of a vector of counters, one per core (or virtual core, in the case of hyper-threading).  Counter increments occurs per-core independently and without locking.  The counter value is aggregated across the per-core counters.  Experiments confirm that core migration errors occur about 1 in 10M counts, an acceptable error rate.&lt;/p&gt;

&lt;p&gt;Implementation&lt;/p&gt;

&lt;p&gt;The key to the fast implementation is the x86  rdtscp  instruction.  It loads the 64-bit timestamp counter into EAX,EDX, and the core / hyper-core (i.e.) &#8220;node&#8221; label into ECX.  We need to implement a module that determines the node count in order to correctly allocate fast counter / timer arrays.&lt;/p&gt;

&lt;p&gt;Portability issues&lt;/p&gt;

&lt;p&gt;Within the class of x86 processors the instruction set varies.  For older intel processors, OS support for finding the core label is needed (mainly access to model-specific registers, as opposed to the rdtscp instruction).  Each of Linux, Windows, Free BSD, Solaris, and OS X have different system calls for accessing msr&#8217;s. The initial implementation should use OS call for obtaining the processor label.   It greatly simplifies the code.&lt;/p&gt;

&lt;p&gt;Testing Results&lt;/p&gt;

&lt;p&gt;Testing shows that per-core counters provide large speed improvements v. single atomic integer with fetch-and-add (15 v. 230 nanos per incr).  Using non-locking v. locking increment instructions (with per-node counters) provides about 2X speedup (15 v. 30 nanos per incr).  Using Linux sched_getcpu() v. inlined rdtscp instructions provides small additional speedup.  It seems very likely that Linux is in fact uses the rdtscp instruction via vsyscall (see: &lt;a href=&quot;http://lxr.linux.no/#linux+v3.8.7/arch/x86/include/asm/vsyscall.h&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://lxr.linux.no/#linux+v3.8.7/arch/x86/include/asm/vsyscall.h&lt;/a&gt; in the Linux cross-reference).  Other OS&#8217;s may not be as smart.&lt;/p&gt;






&lt;p&gt;System Calls&lt;/p&gt;

&lt;p&gt;Windows&lt;/p&gt;

&lt;p&gt;(1) find current core id&lt;/p&gt;

&lt;p&gt;   DWORD cpui;&lt;/p&gt;

&lt;p&gt;   cpuid = GetCurrentProcessorNumber();&lt;/p&gt;

&lt;p&gt;   Requirements&lt;/p&gt;

&lt;p&gt;   Minimum supported client  Windows Vista&lt;/p&gt;

&lt;p&gt;   Minimum supported server  Windows Server 2003&lt;/p&gt;

&lt;p&gt;   Header                    WinBase.h on Windows Server 2003,&lt;/p&gt;

&lt;p&gt;                               Windows Vista, Windows 7, Windows Server 2008,&lt;/p&gt;

&lt;p&gt;                               Windows Server 2008 R2 (with Windows.h);&lt;/p&gt;

&lt;p&gt;                             Processthreadsapi.h on Windows 8, Windows Server 2012&lt;/p&gt;

&lt;p&gt;   Library                   Kernel32.lib&lt;/p&gt;

&lt;p&gt;   DLL                       Kernel32.dll&lt;/p&gt;



&lt;p&gt;(2) Find core count&lt;/p&gt;



&lt;p&gt;   vSYSTEM_INFO sysinfo;&lt;br/&gt;
   GetSystemInfo( &amp;amp;sysinfo );&lt;/p&gt;

&lt;p&gt;   numCPU = sysinfo.dwNumberOfProcessors;&lt;/p&gt;

&lt;p&gt;   Requirements&lt;/p&gt;

&lt;p&gt;   Minimum supported client  Windows 2000 Professional&lt;/p&gt;

&lt;p&gt;   Minimum supported server  Windows 2000 Server&lt;/p&gt;

&lt;p&gt;   Header                    WinBase.h (include Windows.h)&lt;/p&gt;



&lt;p&gt;Linux&lt;/p&gt;

&lt;p&gt;(1) find current core id&lt;/p&gt;


&lt;p&gt;   #include &amp;lt;sched.h&amp;gt;&lt;br/&gt;
   int cpu = sched_getcpu();&lt;/p&gt;

&lt;p&gt;   Requirements&lt;/p&gt;

&lt;p&gt;   glibc 2.6&lt;/p&gt;

&lt;p&gt;(2) Find core count&lt;/p&gt;

&lt;p&gt;   #include &amp;lt;unistd.h&amp;gt;&lt;/p&gt;

&lt;p&gt;   numCPU = sysconf( _SC_NPROCESSORS_ONLN );&lt;/p&gt;

&lt;p&gt;   Requirements&lt;/p&gt;

&lt;p&gt;   This is a POSIX standard function, although _SC_NPROCESSOES_ONLN&lt;/p&gt;

&lt;p&gt;   is non-standard.&lt;/p&gt;




&lt;p&gt;FreeBSD, Mac OS X&lt;/p&gt;

&lt;p&gt;(1) find current core id:&lt;/p&gt;

&lt;p&gt;    tbd&lt;/p&gt;

&lt;p&gt;(2) Find core count:&lt;/p&gt;

&lt;p&gt;   int mib&lt;span class=&quot;error&quot;&gt;&amp;#91;2&amp;#93;&lt;/span&gt;;&lt;/p&gt;

&lt;p&gt;   size_t len = 4;&lt;/p&gt;

&lt;p&gt;   uint32_t numCPU;&lt;/p&gt;

&lt;p&gt;   mib&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt; = CTL_HW;&lt;br/&gt;
   mib&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt; = HW_AVAILCPU;&lt;/p&gt;


&lt;p&gt;   sysctl(mib, 2, &amp;amp;numCPU, &amp;amp;len, NULL, 0);&lt;/p&gt;

&lt;p&gt;   if (numCPU &amp;lt; 1) &lt;/p&gt;
{
       mib[1] = HW_NCPU;
       sysctl( mib, 2, &amp;amp;numCPU, &amp;amp;len, NULL, 0 );
       if (numCPU &amp;lt; 1) numCPU = 1;
   }

&lt;p&gt;   Requirements&lt;/p&gt;

&lt;p&gt;   OS X versions &amp;gt;= 10.2.&lt;/p&gt;




&lt;p&gt;Solaris&lt;/p&gt;


&lt;p&gt;(1) find current core id:&lt;/p&gt;



&lt;p&gt;   #include &amp;lt;sys/processor.h&amp;gt;&lt;br/&gt;
   processorid_t getcpuid(void);&lt;/p&gt;


&lt;p&gt;(2) Find core count:&lt;/p&gt;

&lt;p&gt;   #include &amp;lt;unistd.h&amp;gt;&lt;/p&gt;

&lt;p&gt;   numCPU = sysconf( _SC_NPROCESORS_ONLN );&lt;/p&gt;</description>
                <environment></environment>
        <key id="72248">SERVER-9393</key>
            <summary>Very, very fast counters</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="backlog-server-platform">DO NOT USE - Backlog - Platform Team</assignee>
                                    <reporter username="paul.pedersen">Paul Pedersen</reporter>
                        <labels>
                            <label>move-sa</label>
                            <label>platforms-re-triaged</label>
                    </labels>
                <created>Thu, 18 Apr 2013 16:53:43 +0000</created>
                <updated>Tue, 10 May 2022 21:23:45 +0000</updated>
                                                                            <component>Performance</component>
                                        <votes>0</votes>
                                    <watches>14</watches>
                                                                                                                <comments>
                            <comment id="4539781" author="steven.vannelli" created="Tue, 10 May 2022 21:23:45 +0000"  >&lt;p&gt;Moving this ticket to the Backlog and removing the &quot;Backlog&quot; fixVersion as per our latest policy for using fixVersions. &lt;/p&gt;</comment>
                            <comment id="958284" author="martin.bligh" created="Mon, 6 Jul 2015 12:41:52 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=paul%4010gen.com&quot; class=&quot;user-hover&quot; rel=&quot;paul@10gen.com&quot;&gt;paul@10gen.com&lt;/a&gt; do you still have the code for this somewhere? Would like to replace global atomics by this in various places.&lt;/p&gt;</comment>
                            <comment id="316430" author="schwerin" created="Thu, 18 Apr 2013 17:52:26 +0000"  >&lt;p&gt;On systems for which the current core id is unavailable, you could fallback to threadid % COUNTER_VECTOR_SIZE.  You can steer COUNTER_VECTOR_SIZE up and down based on how averse you are to multiple threads simultaneously using the same counter.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="71224">SERVER-9297</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                                        </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 18 Apr 2013 17:52:26 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 39 weeks, 1 day ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>steven.vannelli@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            1 year, 39 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>schwerin@mongodb.com</customfieldvalue>
            <customfieldvalue>backlog-server-platform</customfieldvalue>
            <customfieldvalue>martin.bligh</customfieldvalue>
            <customfieldvalue>paul.pedersen</customfieldvalue>
            <customfieldvalue>steven.vannelli@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrmwkn:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr9gnb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4315</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hs5667:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>