<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Omri Klinger on Medium]]></title>
        <description><![CDATA[Stories by Omri Klinger on Medium]]></description>
        <link>https://medium.com/@omriklinger?source=rss-20481271b4c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*10eR2U4aV7URYPB_.JPG</url>
            <title>Stories by Omri Klinger on Medium</title>
            <link>https://medium.com/@omriklinger?source=rss-20481271b4c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:39:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omriklinger/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Should we allow custom ddp messages ?]]></title>
            <link>https://medium.com/@omriklinger/should-we-allow-custom-ddp-messages-a5fff26673e2?source=rss-20481271b4c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5fff26673e2</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Omri Klinger]]></dc:creator>
            <pubDate>Mon, 25 Jan 2016 19:22:02 GMT</pubDate>
            <atom:updated>2016-02-02T05:35:21.569Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://www.meteor.com/ddp">ddp protocol</a> lives in the heart of the Meteor framework, its clear and straightforward architecture is great and one of the strengths of this framework.</p><p>On the other hand, sometimes the ddp’s closed nature, limits/encumbers optimizations which are required in order to mitigate scaling issues (re-use subscription between many clients - 500+, sending heavy load of messages 1000+ updates/sec).</p><p>This short blog post includes an overview of a base architecture used in an app I’m developing, my need for custom ddp messages and how it is being implemented into the <a href="https://github.com/meteor/meteor/tree/devel/packages/ddp-client">ddp-client package </a>(one of meteor base packages).</p><p>The solution combines a couple of optimizations. Some of them aren’t related to the ddp, but it will be interesting to get the community&#39;s thoughts on these solutions.</p><h4>A short summary of the optimization:</h4><p>The optimization is called <strong>“batch publication”</strong>. Instead of just re-using the <a href="https://github.com/meteor/meteor/blob/devel/packages/mongo/observe_multiplex.js">multiplexer</a> for same <a href="https://www.meteor.com/livequery">live query</a> in a publication (nice out-of-the-box meteor feature), for each unique publication query we compute once the messages needed to be sent over the socket, and send the stringify message as a batch to all listening clients. We ignore the merge-box so we can grow the number of clients listening to the subscription with almost static memory footprint.</p><p>This solution has many pros (much better performance) and some cons as well (no <a href="https://meteorhacks.com/understanding-mergebox.html">merge box</a>). Like almost any optimization, it depends on your app requirements.</p><p>You can read more details about the optimization and its pros and cons in<strong> </strong><a href="https://medium.com/@omriklinger/how-to-send-1000-updates-sec-per-client-using-meteor-and-stay-alive-88eba7588c36">this blog post<strong> — How to send 2000+ updates/sec per client, using meteor, and stay alive.</strong></a></p><p>This article proposes an option to extend the ddp protocol, so users can specify and extend the variety of allowed messages sent over the meteor connection socket. The proposed solution (PR) <a href="https://github.com/meteor/meteor/pull/6117">#6117</a> is not breaking anything in the protocol nor creating problems for already existing ddp clients (ObjectiveDDP for example). It just allows you to create support for custom messages, so each user who extends his ddp connection with custom messages, will also be able to extend his other ddp clients in the same manner.</p><p>This solution supports two optional ways to extend the ddp messages:</p><p>1. Giving an optional parameter in the connection creation -</p><pre>var options = { customMessages : { updateBatch: function() {} }, …);</pre><pre>DDP.connect(options);</pre><p>2. Extending Meteor.connection or any other connection -</p><pre>_.extend(Meteor.connection._customMessages, { <br> updateBatch: function() {}, <br> subscriptionRedirect: function(){}<br>});</pre><p>Besides this, all that needs to be added to the <a href="https://github.com/meteor/meteor/tree/devel/packages/ddp-client">ddp client</a> code, is a check whether the message is a custom message. This check can be done last after all the original ddp messages.</p><p>For better use I think we should add to the PR an option to extend all newly created connections:</p><pre>DDP.extendCustomMessages(options)</pre><p>Now each new connection that will be created after calling this function, will know about the custom ddp messages.</p><p>I know that there are “hackish” ways to implement this solution without changing the ddp-client package (for example by sending messages through a ddp.added message with different parameters, and changing the client store for this subscription), but I believe that an option to extend the ddp with your own custom messages (<a href="https://docs.google.com/document/d/1JnDlTxx1Atez3eRjkSBVayhKo_FVVma4ag0TXT5SeHw/edit?usp=sharing">BatchUpdate</a>, SubscriptionRedirect for example) is required, and a much cleaner solution.</p><p>The solution of <strong>“batch publication”</strong> heavily depends on the option to extend the ddp protocol, but there are many other interesting solutions that could evolve from this option. Another new ddp message that is being used in a project I’m working on is ‘subscriptionRedirect’. This message tells the user that he should get this subscription from server handling the query that already has the data cached (subscription level routing). I think that an option to extend the ddp protocol will drive a lot of new creative solutions that could help us solve the burning issues regarding the scaling of meteor production apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5fff26673e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to send 1000+ updates/sec per client (using Meteor) and stay alive]]></title>
            <link>https://medium.com/@omriklinger/how-to-send-1000-updates-sec-per-client-using-meteor-and-stay-alive-88eba7588c36?source=rss-20481271b4c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/88eba7588c36</guid>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Omri Klinger]]></dc:creator>
            <pubDate>Mon, 25 Jan 2016 19:20:50 GMT</pubDate>
            <atom:updated>2016-02-02T05:37:06.692Z</atom:updated>
            <content:encoded><![CDATA[<p>The solution presented below has been tested aggressively sharing single subscription between 1000+ users, while sending heavy loads of data for each.</p><h4>The problem -</h4><p>A meteor subscription that is being re-used by many clients is a common need for many apps. For example an uber like app, where a-lot of users see cabs moving on the map (geo-graphic related query that return 2000 results, done by pooling, each doc being updated once a second).</p><h4>The optimization -</h4><p>Disable <a href="https://meteorhacks.com/understanding-mergebox.html">merge box</a> + “Batch publications”.</p><p>In detail -</p><p>First we disable the merge box for the specified subscription , <strong>why ?</strong></p><p>The merge-box requires a-lot of memory. For subscription with 500 clients, the memory required to support it is 500 times the size of the data sent. Moreover, doing diff and building the message for each client, puts a heavy load on your cpu when your data is changing rapidly.</p><p>So <strong>how</strong> do we do it ? and what is the meaning of <strong>batch</strong> <strong>publication</strong> ?</p><p>On each <a href="http://docs.meteor.com/#/full/meteor_publish">publish function</a>, after building the query (from the publication arguments, logic and user roles), we check whether this query is already handled. If so, we add the instance of publication to the query listeners and send the current content of the <a href="https://github.com/meteor/meteor/blob/devel/packages/mongo/observe_multiplex.js">multiplexer</a> to the clients in a batch. We cache this batch message so if another client joins between changes, we can send him the message immediately. We send the message straight over the socket using <a href="https://medium.com/@omriklinger/should-we-allow-custom-ddp-messages-a5fff26673e2">custom ddp message</a> ‘batchUpdate’.</p><p>On each change we compute the diff once (creating a new batch message) and send it to all the clients that are listening to the subscription.</p><p>Because we are disabling the merge-box, we should control merges between different subscriptions manually in the client. An optional convention to solve this, is creating a client collection named after the subscription for each unique subscription.</p><p>For queries that depend on the <a href="https://github.com/meteor/meteor/blob/devel/packages/mongo/polling_observe_driver.js">polling observer</a> there is an option to add an even better optimization — compute the batched message only once we finished the diff of all the changes. This solution requires a minor addition to the <a href="https://github.com/meteor/meteor/tree/devel/packages/mongo">MDG mongo package</a> (I will add this as a PR, in case <a href="https://github.com/meteor/meteor/pull/6117">my original ddp custom messages PR</a> is merged ).</p><p>This solution works great also with <a href="https://github.com/englue/meteor-publish-composite">publishComposite</a> :) and can also save some computation if building of the publish function query is being done dynamically (doing <a href="https://en.wikipedia.org/wiki/Memoization">memoization</a> to the query construction).</p><p>This optimization creates a window for many other optimizations that could be built on top of it. From better representation of the batched data (<a href="http://netflix.github.io/falcor/documentation/jsongraph.html">Netflix — jsongraph</a> or any <a href="http://buildnewgames.com/optimizing-websockets-bandwidth/">other compression</a>) to subscription dynamic routing (“SubscriptionRedirect” — Sending the user to get the subscription from a server that’s already handling it).</p><p>I see the following pros in this optimization:</p><ol><li>Reduced server cpu usage :</li></ol><ul><li>No need to compute each user diff of the <a href="https://meteorhacks.com/understanding-mergebox.html">merge box</a>.</li><li>No need to stringify each user message times the number of users listening for the subscription (DDPCommon.stringifyDDP can takes some time in large multiplies).</li></ul><p>2. Lower usage of server memory (disable the merge box — the memory being used is in the size of the sent data and not the sent data times # of clients)</p><p>3. Better ramp time — a new user that joins a running subscription can immediately get the full image of the subscription.</p><p>4. Optimize client re-rendering — the client can handle the batch subscription as he wants. For example, he can refresh the view after analyzing all of the batch instead of after each message.</p><p>5. It allows more creativity and it’s a base for more optimizations. For example - optimizing the batched message (json-graph or even shortening and group similar messages by order) or even redirecting subscription to the current server that holds this subscription.</p><p>But there are still some cons :</p><ol><li>No <a href="https://meteorhacks.com/understanding-mergebox.html">merge-box</a> (can’t rely on Meteor to join your subscriptions in order to send only the delta — can be easily solved by creating client collection per subscription).</li><li>Needs to handle client re-connections manually (remove data on subscription stop for example).</li><li>Requires patches to some of the most important building blocks of meteor (<a href="https://github.com/meteor/meteor/tree/devel/packages/ddp-client">ddp-client </a>and <a href="https://github.com/meteor/meteor/tree/devel/packages/mongo">mongo</a> packages).</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88eba7588c36" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>