<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:21:46 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-9899] Performance of JavaScript Stored Function on MongoDB Server</title>
                <link>https://jira.mongodb.org/browse/SERVER-9899</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;This is related to javascript stored function in mongodb server. I know all the details about the working and use cases. I am doubtful about one line which is in the official documentation of MongoDB.&lt;/p&gt;

&lt;p&gt;&quot;Note : We do not recommend using server-side stored functions if possible.&quot;&lt;/p&gt;

&lt;p&gt;After moving to V8 JavaScript engine ( improving concurrency issues for javascript queries ) and given the fact this may save us many network round trip time, why this is not recommended?&lt;/p&gt;

&lt;p&gt;Also, if there some performance difference in running javascript queries Vs running normal queries ( given both are able to use index ) ?&lt;/p&gt;

&lt;p&gt;Please link me to supported documentation. Also, it will be much useful, if the reason for such statements are also mentioned in the documentation.&lt;/p&gt;</description>
                <environment>Linux</environment>
        <key id="78559">SERVER-9899</key>
            <summary>Performance of JavaScript Stored Function on MongoDB Server</summary>
                <type id="6" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14720&amp;avatarType=issuetype">Question</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="schwerin@mongodb.com">Andy Schwerin</assignee>
                                    <reporter username="abhishekiitg10@gmail.com">Abhishek Kumar</reporter>
                        <labels>
                            <label>javascript</label>
                            <label>mongodb</label>
                            <label>performance</label>
                    </labels>
                <created>Tue, 11 Jun 2013 06:00:05 +0000</created>
                <updated>Wed, 10 Dec 2014 23:11:59 +0000</updated>
                            <resolved>Tue, 25 Jun 2013 14:34:25 +0000</resolved>
                                    <version>debugging with submitter</version>
                                                    <component>JavaScript</component>
                    <component>Performance</component>
                                        <votes>0</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="360274" author="schwerin" created="Fri, 14 Jun 2013 14:26:30 +0000"  >&lt;p&gt;It is not a statement about the current implementation, but a statement about what may be in the future.  I do not know of any specific reason why performance would differ between a query run in an eval and one run over the network, today.&lt;/p&gt;</comment>
                            <comment id="360264" author="abhishekiitg10@gmail.com" created="Fri, 14 Jun 2013 14:15:50 +0000"  >&lt;p&gt;Is it possible to elaborate on this part, may be using some example?&lt;/p&gt;</comment>
                            <comment id="360260" author="schwerin" created="Fri, 14 Jun 2013 14:13:36 +0000"  >&lt;p&gt;The two situations may have different locking behavior, but do not necessarily.&lt;/p&gt;</comment>
                            <comment id="360149" author="abhishekiitg10@gmail.com" created="Fri, 14 Jun 2013 10:19:56 +0000"  >&lt;p&gt;Just want to confirm what I understood is correct.&lt;br/&gt;
The normal read and read lock acquired using eval is having some difference. The read lock of eval having &apos;typical database locking behavior&apos; is little expensive.&lt;/p&gt;</comment>
                            <comment id="359617" author="schwerin" created="Thu, 13 Jun 2013 17:33:37 +0000"  >&lt;p&gt;The &quot;nolock&quot; argument to eval causes a more typical database locking behavior to apply.  The query execution engine may yield the read lock periodically.  As to your last question, I recommend conducting the same experiment again, to convince yourself, but queries without a $where component will not use javascript evaluation to test each document.&lt;/p&gt;</comment>
                            <comment id="358323" author="abhishekiitg10@gmail.com" created="Wed, 12 Jun 2013 02:44:46 +0000"  >&lt;p&gt;Thanks for making me understand the difference. I run the test as you told, and clearly seeing the big difference in response time. &lt;/p&gt;

&lt;p&gt;Please let me know, if eval with nolock option, yields the read lock or not? The documentation is not having this information.&lt;br/&gt;
Also if there are normal read queries inside the eval, are they treated as JavaScript queries or normal queries?&lt;/p&gt;</comment>
                            <comment id="358113" author="schwerin" created="Tue, 11 Jun 2013 21:29:11 +0000"  >&lt;p&gt;There will be a performance difference in the two queries that you describe.  Both of them will be able to use the {{&lt;/p&gt;
{a: 1}
&lt;p&gt;}} index, but the form that uses &lt;tt&gt;$where&lt;/tt&gt; to examine the value of &lt;tt&gt;b&lt;/tt&gt; will pay a constant factor overhead for invoking javascript execution on documents that match &lt;tt&gt;a&lt;/tt&gt;.  I recommend that you construct a simple collection of a few hundred thousand documents, where a few tens of thousands have {{&lt;/p&gt;
{a: 1}
&lt;p&gt;}}, and compare performance of the two queries, to get a sense for the amount of overhead.  Of course, if the expression you wish to compare is not expressible in the current version of the query language, you may have to use &lt;tt&gt;$where&lt;/tt&gt; form.  It is typically worth avoiding, however.&lt;/p&gt;</comment>
                            <comment id="358073" author="abhishekiitg10@gmail.com" created="Tue, 11 Jun 2013 20:56:38 +0000"  >&lt;p&gt;@Andy&lt;br/&gt;
Thanks for the comment.&lt;br/&gt;
Here, from your comment, I understand the restriction, so might be because of that it is not recommended. Also, I want to know if there is some performance related differences also exists with a JavaScript query Vs normal query. Say, for below example:&lt;br/&gt;
db.collection.ensureIndex(&lt;/p&gt;
{ a : 1 }
&lt;p&gt;)&lt;br/&gt;
db.collection.find(&lt;/p&gt;
{ a : 1, b : 1 }
&lt;p&gt;)&lt;br/&gt;
db.collection.find(&lt;/p&gt;
{ a : 1, $where : &quot;this.b=1&quot;}
&lt;p&gt;)&lt;/p&gt;</comment>
                            <comment id="357911" author="schwerin" created="Tue, 11 Jun 2013 18:16:36 +0000"  >&lt;ol&gt;
	&lt;li&gt;Stored javascript functions can only issue queries when executed via the &quot;eval&quot; command, which requires full administrative permissions in MongoDB 2.4 (&lt;a href=&quot;http://docs.mongodb.org/manual/reference/command/eval/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/reference/command/eval/&lt;/a&gt;).&lt;/li&gt;
	&lt;li&gt;The &quot;eval&quot; command is not compatible with sharded collections.&lt;/li&gt;
	&lt;li&gt;Stored functions are not compatible (to my knowledge) with sharded mapreduce, though I may be mistaken, here.&lt;/li&gt;
&lt;/ol&gt;
</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="78558">SERVER-9898</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 11 Jun 2013 18:16:36 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        10 years, 35 weeks, 5 days 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>false</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            10 years, 35 weeks, 5 days 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>abhishekiitg10@gmail.com</customfieldvalue>
            <customfieldvalue>schwerin@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrmqjz:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>71798</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_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</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|hsskrj:</customfieldvalue>

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