بعد 3 سنوات، مذكرة للأشخاص الذين يتصفحون هنا. فكر في لماذا تريد استخدام الوسيطة الوسيطة للرسائل. إذا كان السبب هو توزيع المهام داخل كتلة، والنظر في الكرفس. وهو يعمل على مستوى أعلى من التجريد من حلول على غرار مق، يستخدم رابتمق لنقل الرسائل، ولكن لديه دعم متميز للدلالات مهمة محددة. نداش كريس جونسون 28 أغسطس 13 في 20:22 17 أجوبة تحرير: كان جوابي الأولي تركيز قوي على أمكب. قررت أن إعادة كتابته لتقديم وجهة نظر أوسع حول هذا الموضوع. هذه التكنولوجيات 3 الرسائل لديها نهج مختلفة لبناء أنظمة موزعة: رابتمق هي واحدة من التنفيذ الرائدة للبروتوكول أمكب (جنبا إلى جنب مع أباتشي كبيد). ولذلك، فإنه ينفذ بنية وسيط، وهذا يعني أن الرسائل في قائمة الانتظار على عقدة مركزية قبل أن يتم إرسالها إلى العملاء. هذا النهج يجعل رابيتمق من السهل جدا للاستخدام ونشر، لأن سيناريوهات متقدمة مثل التوجيه، موازنة التحميل أو استمرار الطابور رسالة معتمدة في بضعة أسطر فقط من التعليمات البرمجية. ومع ذلك، فإنه يجعل أيضا أقل قابلية وبطء لأن عقدة مركزية يضيف الكمون ومغلفات الرسالة كبيرة جدا. زيرومق هو نظام الرسائل خفيفة الوزن جدا المصممة خصيصا لارتفاع سيناريوهات الكمون التبسيط مثل واحد يمكنك أن تجد في العالم المالي. زمك يدعم العديد من سيناريوهات الرسائل المتقدمة ولكن خلافا ل رابتمق، سيكون لديك لتنفيذ معظمهم بنفسك من خلال الجمع بين قطع مختلفة من الإطار (على سبيل المثال مآخذ والأجهزة). زمك مرنة جدا ولكن سيكون لديك لدراسة 80 صفحة أو نحو ذلك من الدليل (الذي أوصي القراءة لأي شخص كتابة نظام موزعة، حتى لو كنت لا تستخدم زمق) قبل أن تكون قادرة على القيام بأي شيء أكثر تعقيدا من إرسال رسائل بين 2 أقرانهم. أكتيفمق هو في وسط الأرض. مثل زمق، فإنه يمكن نشرها مع كل وسيط و P2P طبولوجيا. مثل رابيتمق، وأسهل لتنفيذ سيناريوهات متقدمة ولكن عادة على حساب الأداء الخام. في سكين الجيش السويسري من الرسائل :-). وأخيرا، جميع المنتجات 3: أبيس العميل للغة الأكثر شيوعا (C، جافا نت، بيثون، فب، روبي،) لديها وثائق قوية معتمدة بنشاط أجاب نوف 6 09 في 13:46 نواز 209k 9679 65 9679 461 9679 671 بينما صحيح، لست متأكدا مما إذا كان اعتماد أمكب علاقة قوية مع السؤال الأصلي. وأعتقد أن هناك اعتبارات أكثر أهمية لاختيار واحد من قائمة انتظار الرسائل من بروتوكول الأسلاك الأساسية التي يستخدمها. نداش ستدسمان 13 مايو 10 في 22:26 السؤال لا يشير إلى أمكب، ولكن هذه الإجابة تركز على أمكب. إذا كان علينا أن نفترض جمس كشرط ثم الجواب سيكون في الأساس العكس: أكتيفيمق هو الأكثر شعبية، رابيتمق لديه بعض الدعم الذي ينبغي أن تعمل على الأرجح. إذا لم يكن هناك بروتوكول سلك مفترض: انظر إجابات أخرى. نداش فليتش ديك 2 10 في 10:53 بعد أن عملت في رابيتمق و أكتيفمق أنصحك البقاء بعيدا عن أكتيفمق. الإصدارات هي عربات التي تجرها الدواب جدا، وكان لي أي نهاية المشاكل مع آلات تسير وتسرب الذاكرة الخ رابيتمق من ناحية أخرى يعمل فقط. بعد أن توصيله في I39ve لم يكن أبدا للنظر في الأمر مرة أخرى. انها تفعل فقط ما تحتاج إليه. إذا كنت ترغب في بلدي رابتمق تعليمي بسيط على بلدي بلوق جارلاببيتمق-ج - البرنامج التعليمي نداش كيلي نوفمبر 20 11 في 2:57 رسالة الطابور الرسائل خوادم الرسائل طابور الرسائل متوفرة في لغات مختلفة، إرلانغ (رابتمق)، C (بينستالكد)، روبي ( ستارلينغ أو سبارو)، سكالا (كيستريل، كافكا) أو جافا (أكتيفمق). نظرة عامة قصيرة يمكن العثور عليها هنا مكتوبة من قبل أليكس ماكاو سبارو هو طابور خفيفة الوزن مكتوبة في روبي الذي يتحدث ميمكاش كتبه بلين كوك في تويتر ستارلينغ هو خادم قائمة انتظار الرسائل على أساس ميمكاشيد مكتوب في مخازن روبي وظائف في الذاكرة (طابور رسالة) الوثائق: بعض الدروس الجيدة، على سبيل المثال رايلسكاست حول ستارلينغ و وركلينغ أو هذا بلوق وظيفة حول زرزور كتبه روبي مؤشر ستارلينغ استنساخ مكتوب في سكالا (ميناء ستارلينغ من روبي إلى سكالا) يتم تخزين الطوابير في الذاكرة، ولكن تسجيل على القرص رابتمق هو خدمة قائمة انتظار الرسائل في إرلانغ مخازن وظائف في الذاكرة (قائمة انتظار الرسائل) أكتيفيمق هو وسيط رسالة مفتوحة المصدر في جافا كتبه فيلوتيك، Inc. لتحسين وقت الاستجابة لتطبيق فاسيبوك في الذاكرة خدمة ورككوي مكتوبة في الغالب في C دوكومنت: nubyonrailsarticlesabout - هذا بلوق-الفاصوليا-الرسائل-طابور كتب في لينكيدين في سكالا التي يستخدمها لينكيدين لإخراج معالجة جميع الصفحة وغيرها من وجهات النظر الافتراضية لاستخدام الثبات، يستخدم نظام التشغيل ذاكرة التخزين المؤقت للقرص للبيانات الساخنة (لديها أعلى الإنتاجية ثم أي من ما سبق تمكين استمرار) يدعم كلا على الخط كما خارج الخط تجهيز مكتبة المقبس الذي يعمل كإطار التزامن أسرع من تكب، للمنتجات متفاوت المسافات والحوسبة الفائقة يحمل رسائل عبر إنبروك ، إيبك، تكب، الإرسال المتعدد N-تو-N عبر فانوت، بوبسوب، خط أنابيب، ريكست-ريبلي أسينتش إو للتطبيقات متعددة الوظائف تمرير الرسائل إيغلمق هو مصدر مفتوح، عالية الأداء وخفيفة الوزن مدير طابور. كتب في C مخازن جميع البيانات في الذاكرة ودعم استمرار. لديها بروتوكول الخاصة بها. يدعم العمل مع طوابير، والطرق والقنوات. أيرونمق كتب في الذهاب خدمة الطابور المدارة بالكامل متاح على حد سواء كما نسخة سحابة وعلى فرضية آمل أن يكون هذا سيكون مفيدا بالنسبة لنا. مصدر مايكل - تريد وضع أكثر من ذلك بقليل المشكلة هي التسليم في الوقت الحقيقي في نظام دردشة مجموعة مقرها. إذا فهم I39m بشكل صحيح، فإنك تتحدث عن آلية تخزين دائمة للرسائل كنقطة نهاية (صندوق الوارد) إذا كان الأمر كذلك، فإنه لا يناسب الفاتورة، ويريدون أن يتم تسليم الدردشة على الفور، والعملاء ليكونوا مشتركين مباشرين بقدر ما أستطيع أن أقول وجود طن من طوابير على أساس الموضوع ليست الأمثل استخدام حالة ندش جوش 16 أكتوبر 10 في 20:38 انها حقا يعتمد على استخدام الخاص بك القضية. مقارنة 0MQ مع أكتيفيمق أو رابيتمق ليست عادلة. أكتيفيمق و رابيتمق هي أنظمة التراسل التي تتطلب التثبيت والإدارة. أنها توفر فيتوريسويز أكثر بكثير من زيرومق. لديهم قوائم الانتظار المستمر الحقيقي، ودعم المعاملات الخ زيرومق هو رسالة خفيفة تنفيذ مأخذ الموجهة. بل هو أيضا مناسبة لفي عملية غير متزامن البرمجة. فمن الممكن لتشغيل نظام التراسل المؤسسة على زيرومق، ولكن سيكون لديك لتنفيذ الكثير من تلقاء نفسها. أكتيفمق، رابيتمق، وبسفهير مق أمب مسمق هي المؤسسة رسالة الطابور زيرومق هو رسالة موجهة إيبك المكتبة. ثيريز مقارنة بين رابيتمق و أكتيفمق هنا. من خارج منطقة الجزاء، يتم تكوين أكتيفمق لضمان تسليم الرسالة - والتي يمكن أن تعطي الانطباع بطيئا مقارنة مع أنظمة الرسائل أقل موثوقية. يمكنك دائما تغيير التكوين للأداء إذا كنت ترغب والحصول على الأقل على النحو الجيد كما في أي نظام الرسائل الأخرى. على الأقل لديك هذا الخيار. ثيرس الكثير من المعلومات عن المنتديات و أكتيفمق أسئلة وأجوبة لتكوين التحجيم والأداء وتوافر عالية. أيضا، سوف أكتيفيمق دعم أمكب 1.0 عندما يتم الانتهاء من المواصفات، جنبا إلى جنب مع غيرها من الأشكال الأسلاك، مثل ستومب. آخر زائد ل أكتيفمق هو مشروع أباتشي، لذلك هناك تنوع في المجتمع المطور - وليس مرتبطة بشركة واحدة. أجاب 20 أكتوبر 09 في 17:26 I هيف نوت أوسد أكتيفمق أو رابيتمق ولكن قد استخدمت زيرومق. الفرق الكبير كما أراه بين زيرومق و أكتيفمق الخ هو أن 0MQ هو بروكيرليس وليس لديها بنيت في ريليابيلتي لتسليم الرسالة. إذا كنت تبحث عن وسيلة سهلة لاستخدام الرسائل أبي دعم العديد من أنماط الرسائل، والنقل، والمنصات وربط اللغة ثم 0MQ هو بالتأكيد يستحق نظرة. إذا كنت تبحث عن منصة الرسائل في مهب كامل ثم 0MQ قد لا يصلح مشروع القانون. انظر zeromq. orgdocs: كوكبوك فور بلنتي إكسامبلز أوف هاو 0MQ كان بي وسد. أنا بنجاح باستخدام 0MQ لرسالة تمرير في تطبيق مراقبة استخدام الكهرباء (انظر rwscott. co. uk20100614currentcost-إنفي-cc128-بارت-1) أجاب 24 أغسطس 10 في 7:28 إم باستخدام زيرمق. أردت رسالة بسيطة تمرير النظام وأنا لا تحتاج إلى مضاعفات وسيط. كما أنني لا أريد ضخمة جافا نظام المشاريع الموجهة. إذا كنت تريد نظام سريع وبسيط وتحتاج إلى دعم لغات متعددة (يمكنني استخدام C و. نيت) ثم إد يوصي النظر في 0MQ. أجاب 28 يوليو 10 في 16:18 أيضا باستخدام زمق في بيئة سيسي. سريع جدا. باستخدام نمط الوسيط. ومناسبة جيدة لدينا في الوقت الحقيقي فواب مشاهدة الكلب التطبيق تفعل الدقيقة بتس لمزارع خوادم سيب كامايليو. بالتأكيد أنا يمكن أن أكتب وسيط متطورة جدا باستخدام زمق، ولكن تقييم بعض المنتجات الإضافية قبل الالتزام بذلك. نداش روكيتروي نوفمبر 7 13 في 06:26 يمكنني فقط إضافة بلدي سنتا 2 حول أكتيفمق ولكن لأن هذا هو واحد من الأكثر شعبية: اللغة التي تريد أن تكتب في قد تكون مهمة. على الرغم من أن أكتيفيمق لديه عميل لمعظم، تنفيذ C بعيدة عن الانتهاء مقارنة مع مكتبة جافا. وهذا يعني أن بعض الوظائف الأساسية غير مستقر (فشل في تجاوز البروتوكول. فشل في بعض الحالات، لا دعم إعادة التسليم) وغيرها ببساطة ليس هناك. منذ. NET لا يبدو أن كل ما هو مهم للمشروع، والتنمية تبطئ بدلا وهناك لا يبدو أن يكون أي خطة الافراج عنهم. غالبا ما يتم كسر الجذع حتى إذا كنت تنظر في هذا، قد ترغب في النظر في المساهمة في المشروع إذا كنت تريد الأمور للمضي قدما. ثم هناك أكتيفمق نفسها التي لديها الكثير من الميزات لطيفة ولكن بعض القضايا غريبة جدا أسويل. نحن نستخدم فيوز (التقدم) نسخة من أكتيفيمق لأسباب الاستقرار ولكن حتى ذلك الحين هناك بضعة من الأخطاء الغريبة التي تريد أن نأخذ في الاعتبار: وسطاء التي توقف عن إرسال رسائل في بعض المناسبات أخطاء مجلة جعل قائمة الانتظار تظهر الرسائل التي ليست هناك بعد الآن (أنها لا تحصل على تسليمها إلى المستهلك ولكن لا يزال) لا تزال الأولوية لم تنفذ (على قائمة القضايا منذ بداية النوع البشري) الخ الخ جميع وجميع، هو منتج جميل جدا إذا كنت تستطيع أن تعيش مع القضايا: A) لا تخافوا على المشاركة بنشاط عند استخدام. NET B) تطوير في جافا -) أجاب أكتوبر 29 09 في 09:47 تحديث طفيفة: منذ حين، كهادب هو مخزن استمرار الافتراضي ل أكتيفمق. ومع ذلك: أنها ليست مستقرة على الإطلاق. في تجاربنا، رأينا الفساد قاعدة البيانات (بعض ريستورابل، والبعض الآخر يكلفنا ما يقرب من 15.000.000 رسائل) حذار من هذا نداش نوكتريس أبريل 4 11 في 8:25 زيرومق هو حقا مع طوابير صفر وهو خطأ حقا فإنه لا طوابير هاف ، والموضوعات، والمثابرة، لا شيء أنها ليست سوى الوسيطة لمآخذ أبي. إذا كان هو ما كنت تبحث بارد خلاف ذلك ننسى أنها ليست مثل أكتيفمق أو رابيتمق. هناك مقارنة بين ميزات وأداء رابيتمق أكتيفمق و كبيد تعطى في bhavin. directirabbitmq - مقابل أباتشي-أكتيفيمق-فس-أباتشي-كبيد شخصيا لقد حاولت كل ثلاثة أعلاه. رابيتمق هو أفضل أداء الحكمة وفقا لي، ولكن لم يكن لديك تجاوز الفشل وخيارات الاسترداد. أكتيفمق لديه معظم الميزات، ولكن هو أبطأ. تحديث. هورنيتك هو أيضا خيار يمكنك النظر في، فمن جمس شكوى، وهو خيار أفضل من أكتيفمق إذا كنت تبحث عن حل القائم على جمس. أجاب 23 أغسطس 10 في 11:05 كتبت عن تجربتي الأولية بشأن أمكب، كبيد و زيرومق هنا: ron. shoutboot20100925is-أمبق-فور-يو رأيي الشخصي هو أن أمكب على ما يرام إذا كنت حقا بحاجة إلى مرافق الرسائل المستمرة وليس قلقة جدا من أن الوسيط قد يكون عنق الزجاجة. أيضا، العميل C مفقود حاليا ل أمكب (كبيد لم يفوز دعم بلدي غير متأكد من العميل أكتيفمق ومع ذلك)، ولكن ربما العمل في التقدم. زيرومق قد يكون الطريق خلاف ذلك. أجابيد سيب 25 10 في 20:13 إيف المستخدمة أكتيفمق في بيئة الإنتاج لحوالي 3 سنوات الآن. في حين أنه يحصل على هذه المهمة، بطانة الإصدارات من المكتبات العميل التي تعمل بشكل صحيح ويمكن خلل يمكن أن يكون مشكلة. كانت تبحث حاليا للانتقال إلى رابيتمق. أجاب 14 مايو 11 في 18:12 هناك بعض النقاش في تعليقات هذه المشاركة بلوق. حول تويتر كتابة طابور الرسائل الخاصة بهم، والتي قد تكون مثيرة للاهتمام. ستيف فعل الحمل واسعة واختبار الإجهاد من أكتيفيمق، رابتمق، الخ أكتيفمق هو في الواقع بطيئة جدا (أبطأ بكثير من كيستريل)، رابتمق تعطل باستمرار مع الكثير من المنتجين وعدد قليل جدا من المستهلكين. ربما لن يكون تحميل تويتر مثل في البداية ولكن :) أجاب :) أبر 8 09 في 20:33 عدد قليل من التطبيقات لديها العديد من التكوينات ضبط كما أكتيفمق. بعض الميزات التي تجعل أكتيفمق تبرز هي: شكلي بريفيتش الحجم. خيوط شكلي. فشل تجاوز شكلي. الإخطار الإداري شكلي للمنتجين. تفاصيل في: أجابيد جول 20 10 في 19:17 أبي، إيت آل كوميس دون تو يور وس كيس. بدلا من الاعتماد على حساب إلسس شخص من حالة استخدامها، لا تتردد في نشر حالة الاستخدام الخاص بك إلى قائمة رابتمق مناقشة. سوف يطلب على تويتر الحصول على بعض الردود أيضا. أطيب التمنيات، أجاب أليكسيس مايو 18 09 في 13:07 حول زيرومق أكا 0MQ، كما كنت قد تعرف بالفعل، واحد الذي سوف تحصل على معظم الرسائل في ثوان (كانوا حوالي 4 ملايين في الثانية على ملقم ريف آخر مرة أنا فحص)، ولكن كما قد تكون تعرف بالفعل، الوثائق غير موجودة. سيكون لديك صعوبة في العثور على كيفية بدء الخادم (ق)، ناهيك عن كيفية استخدامها. أعتقد أن هذا جزئيا لماذا لا أحد ساهم حوالي 0MQ حتى الان. أجاب 15 مايو 10 في 3:06 وهناك أمثلة في كتاب الطبخ zeromq. orgdocs: كتاب الطبخ وهناك دليل api. zeromq. orgzmq. html. نداش نيك يوليو 28 10 في 16:13 في حين زمق سريع ولها أبي سهلة، نضع في اعتبارنا هذا: أي استمرار، لا المعاملات. لا كشف للمستهلكين بطيئة أو بطيئة (الرسائل ببساطة الحصول على إسقاط دون أي إخطار لبرنامج المنتج). سيدينوت: زمق هو سيرفيرليس، لذلك كنت won39t العثور على مستندات لبدء الخوادم. لديهم خادم وكيل إذا كنت بحاجة إلى شيء من هذا القبيل على الرغم من. ندش نوس جول 28 10 في 16:33 إذا كنت مهتما أيضا في التطبيقات التجارية، يجب أن نلقي نظرة على السكينة من بلدي القنوات. وتستخدم السكينة بشكل كبير في صناعة الخدمات المالية لمنصات توزيع السعر المنخفض والكمون على نطاق واسع. هناك دعم لمجموعة واسعة من لغات البرمجة العميل عبر المؤسسة، على شبكة الإنترنت والمجالات النقالة. قدرات تجميع متقدمة للغاية وتستحق نظرة إذا كان ها شفافة أو موازنة التحميل المهم بالنسبة لك. السكينة مجاني لتحميل لأغراض التنمية. أوسلاشمق هو نظام الرسائل، أو الوسيطة الموجهة نحو الرسائل، إذا كنت سوف. تستخدم في بيئات متنوعة مثل الخدمات المالية، وتطوير اللعبة، وأنظمة جزءا لا يتجزأ، والأبحاث الأكاديمية والفضاء. تعمل أنظمة المراسلة أساسا كرسائل فورية للتطبيقات. تطبيق يقرر إبلاغ الحدث إلى تطبيق آخر (أو تطبيقات متعددة)، فإنه يجمع البيانات المراد إرسالها، يضرب زر الإرسال وهناك نحن غومداشث نظام الرسائل يعتني بقية. على عكس الرسائل الفورية، على الرغم من أن أنظمة الرسائل ليس لديها واجهة المستخدم الرسومية، ولا يفترض أي إنسان في نقاط النهاية قادرة على التدخل الذكي عندما يحدث شيء خاطئ. وبالتالي فإن أنظمة التراسل يجب أن تكون متسامحة مع الأخطاء وأكثر من الرسائل الفورية الشائعة. وقد تم تصميم أوسلاشمق أصلا باعتباره نظام الرسائل فائقة السرعة لتداول الأسهم، وبالتالي كان التركيز على الأمثل القصوى. وقد أنفقت السنة الأولى من المشروع على وضع منهجية للمقارنة ومحاولة تحديد بنية تتسم بأكبر قدر ممكن من الكفاءة. وفي وقت لاحق، تقريبا في السنة الثانية من التنمية، تحول التركيز إلى توفير نظام عام لبناء التطبيقات الموزعة ودعم أنماط الرسائل التعسفية، وآليات النقل المختلفة، وربط اللغة التعسفي، وما إلى ذلك. وخلال السنة الثالثة كان التركيز أساسا على تحسين قابلية الاستخدام وتسطيح منحنى التعلم. اعتمدنا أبي بسد مآخذ، حاولت تنظيف الدلالات من أنماط الرسائل الفردية، وهلم جرا. ونأمل أن يعطي هذا الفصل نظرة ثاقبة حول كيفية ترجمة الأهداف الثلاثة المذكورة أعلاه إلى العمارة الداخلية ل أوسلاشمق، وتقديم بعض النصائح لأولئك الذين يكافحون مع نفس المشاكل. منذ عامها الثالث أوسلاشمق قد تجاوزت كودباس هناك مبادرة لتوحيد بروتوكولات الأسلاك التي يستخدمها، والتنفيذ التجريبي لنظام الرسائل مثل أوسلاشمق داخل نواة لينكس، الخ هذه الموضوعات ليست مشمولة في هذا الكتاب. ومع ذلك، يمكنك التحقق من الموارد على الانترنت لمزيد من التفاصيل: 250bpmconcepts. groups. googlegroupsp-بحث-المجموعة. و 250bpmhits. 24.1. التطبيق مقابل مكتبة أوسلاشمق هي مكتبة، وليس خادم الرسائل. استغرق الأمر عدة سنوات العمل على بروتوكول أمكب، محاولة صناعة المالية لتوحيد بروتوكول الأسلاك ل ميساجينغمداشوريتينغ الأعمال التنفيذ مرجعية لذلك والمشاركة في العديد من المشاريع على نطاق واسع تعتمد بشكل كبير على الرسائل تيشنولوجيمداشتو ندرك أن ثيريس شيء خاطئ مع نموذج كلينتسيرفر الكلاسيكية من خادم الرسائل الذكية (وسيط) والبريد الرسائل العملاء. كان شاغلنا الأساسي في ذلك الوقت مع الأداء: إذا كان هناك ملقم في الوسط، كل رسالة لديها لتمرير الشبكة مرتين (من المرسل إلى وسيط ومن الوسيط إلى المتلقي) إحداث عقوبة من حيث الكمون والإنتاجية. وعلاوة على ذلك، إذا تم تمرير جميع الرسائل من خلال وسيط، في مرحلة ما من المقرر أن تصبح عنق الزجاجة. وكان الشاغل الثانوي يتعلق بعمليات نشر واسعة النطاق: فعندما يعبر النشر الحدود التنظيمية، لا ينطبق مفهوم السلطة المركزية التي تدير كامل تدفق الرسالة. لا توجد شركة على استعداد للتنازل عن السيطرة على خادم في شركة مختلفة هناك أسرار تجارية و ثيرس المسؤولية القانونية. والنتيجة في الممارسة هي أن ثيريس خادم الرسائل واحد لكل شركة، مع جسور مكتوبة بخط اليد لربطه إلى أنظمة المراسلة في الشركات الأخرى. وبالتالي فإن النظام البيئي بأكمله هو مجزأة إلى حد كبير، والحفاظ على عدد كبير من الجسور لكل شركة المعنية لا يجعل الوضع أفضل. لحل هذه المشكلة، نحن بحاجة إلى بنية موزعة بالكامل، وهي بنية حيث يمكن أن يحكم كل مكون من قبل كيان تجاري مختلف. وبالنظر إلى أن وحدة الإدارة في العمارة المستندة إلى الخادم هو الملقم، يمكننا حل المشكلة عن طريق تثبيت ملقم منفصل لكل مكون. في مثل هذه الحالة يمكننا مواصلة تحسين التصميم من خلال جعل الخادم والمكون مشاركة نفس العمليات. ما ننتهي به هو مكتبة الرسائل. وقد بدأ أوسلاشمق عندما حصلنا على فكرة حول كيفية جعل الرسائل العمل دون خادم مركزي. انها تتطلب تحويل مفهوم كامل من الرسائل رأسا على عقب واستبدال نموذج مخزن مركزي مستقل للرسائل في وسط الشبكة مع نقطة النهاية الذكية، بنية الشبكة البكم على أساس مبدأ من طرف إلى طرف. وكانت النتيجة الفنية لهذا القرار أن أوسلاشمق، منذ البداية، كانت مكتبة، وليس تطبيق. في هذه الأثناء كنا قادرين على إثبات أن هذا العمارة على حد سواء أكثر كفاءة (أقل الكمون، وارتفاع الإنتاجية) وأكثر مرونة (من السهل لبناء طبولوجيا معقدة التعسفية بدلا من أن تكون مرتبطة نموذج المحور التقليدي وتحدث). بيد أن أحد النتائج غير المقصودة هو أن اختيار نموذج المكتبة يحسن إمكانية استخدام المنتج. مرارا وتكرارا للمستخدمين التعبير عن سعادتهم حول حقيقة أنها لم يكن لديك لتثبيت وإدارة خادم الرسائل مستقل. اتضح أن عدم وجود ملقم هو الخيار المفضل لأنه يقلل من التكلفة التشغيلية (لا حاجة أن يكون مسؤول إدارة الرسائل) ويحسن الوقت إلى السوق (لا حاجة للتفاوض على الحاجة لتشغيل الخادم مع العميل، و إدارة أو فريق العمليات). والدرس المستفاد هو أنه عند بدء مشروع جديد، يجب أن تختار تصميم المكتبة إذا كان ذلك ممكنا على الإطلاق. من السهل جدا لإنشاء تطبيق من مكتبة عن طريق استدعاء ذلك من برنامج تافهة ومع ذلك، من المستحيل تقريبا لإنشاء مكتبة من القائمة التنفيذية القابلة للتنفيذ. توفر المكتبة المزيد من المرونة للمستخدمين، وفي الوقت نفسه تجنيبهم جهود إدارية غير تافهة. 24.2. المتغيرات العالمية العالمية العالمية لا تلعب بشكل جيد مع المكتبات. قد يتم تحميل مكتبة عدة مرات في العملية ولكن حتى ثيريس فقط مجموعة واحدة من المتغيرات العالمية. ويبين الشكل 24.1 مكتبة أوسلاشمق المستخدمة من مكتبتين مختلفتين ومستقلتين. ثم يستخدم التطبيق كل من تلك المكتبات. الشكل 24.1: أوسلاشمق المستخدمة من قبل المكتبات المختلفة عندما يحدث مثل هذا الوضع، كل من أوسلاشمق الوصول إلى المتغيرات نفسها، مما أدى إلى ظروف السباق، فشل غريب وسلوك غير معروف. لمنع هذه المشكلة، مكتبة أوسلاشمق ليس له متغيرات عالمية. بدلا من ذلك، يكون مستخدم المكتبة مسؤولا عن إنشاء الحالة العالمية بشكل صريح. الكائن الذي يحتوي على الحالة العالمية يسمى السياق. في حين أن سياق منظور المستخدمين تبدو أكثر أو أقل مثل مجموعة من المواضيع عامل، من منظور أوسلاشمق مجرد كائن لتخزين أي حالة عالمية أننا نحتاج إلى الحاجة. في الصورة أعلاه، سيكون ليبا سياقها الخاص و ليب سيكون لها أيضا. لن يكون هناك سبيل لأحدهم لكسر أو تخريب الآخر. الدرس هنا واضح جدا: لا تستخدم الحالة العالمية في المكتبات. إذا فعلت ذلك، من المرجح أن كسر مكتبة عندما يحدث أن مثيل مرتين في نفس العملية. 24.3. الأداء عندما بدأ أوسلاشمق، كان هدفه الأساسي لتحسين الأداء. يتم التعبير عن أداء أنظمة المراسلة باستخدام مقياسين: يمكن نقل عدد كبير من الرسائل خلال مقدار معين من الوقت ووقت الاستجابة لوقت طويل يستغرق وصول رسالة من نقطة نهاية إلى أخرى. أي مقياس يجب أن نركز على ما العلاقة بين اثنين ليس من الواضح تشغيل الاختبار، وتقسيم الوقت الإجمالي للاختبار من قبل عدد من الرسائل مرت وما تحصل عليه هو الكمون. تقسيم عدد من الرسائل حسب الوقت وما تحصل عليه هو الإنتاجية. وبعبارة أخرى، الكمون هو القيمة العكسية للإنتاجية. تافهة، يمين بدلا من البدء في الترميز على الفور قضينا بعض الأسابيع التحقيق في مقاييس الأداء بالتفصيل ووجدنا أن العلاقة بين الإنتاجية والكمون هو أكثر دقة من ذلك بكثير، وغالبا ما تكون مقاييس غير بديهية تماما. تخيل إرسال رسائل إلى B. (انظر الشكل 24.2). الوقت الإجمالي للاختبار هو 6 ثوان. هناك 5 رسائل مرت. وبالتالي فإن الإنتاجية هي 0.83 مسغسيك (56) و الكمون هو 1.2 ثانية (65)، الحق إلقاء نظرة على الرسم البياني مرة أخرى. يستغرق وقتا مختلفا لكل رسالة للحصول على من A إلى B: 2 ثانية، 2.5 ثانية، 3 ثانية، 3.5 ثانية، 4 ثانية. المتوسط هو 3 ثوان، وهو بعيد جدا عن حسابنا الأصلي من 1.2 ثانية. يوضح هذا المثال المفاهيم الخاطئة التي يميل إليها الأشخاص بشكل حدسي لتحقيق مقاييس الأداء. الآن إلقاء نظرة على الإنتاجية. الوقت الإجمالي للاختبار هو 6 ثوان. ومع ذلك، في A يستغرق سوى 2 ثانية لإرسال جميع الرسائل. من وجهة نظر الإنتاجية هو 2.5 مسغسيك (52). في B يستغرق 4 ثوان لتلقي جميع الرسائل. لذلك من منظور بس الإنتاجية هو 1.25 مسغسيك (54). لا أي من هذه الأرقام يطابق حسابنا الأصلي من 1.2 مسغسيك. لجعل قصة قصيرة قصيرة، الكمون والإنتاج هما مقياسان مختلفان أن الكثير هو واضح. والشيء المهم هو فهم الفرق بين الاثنين وعلاقتهما المتبادلة. يمكن قياس الكمون فقط بين نقطتين مختلفتين في النظام ثيرس لا شيء مثل الكمون عند النقطة A. كل رسالة لديها الكمون الخاصة بها. يمكنك متوسط عدد مرات ظهور رسائل متعددة، ومع ذلك، لا شيء مثل الكمون من مجموعة من الرسائل. ومن ناحية أخرى، لا يمكن قياس الإنتاجية إلا في نقطة واحدة من النظام. ثيرس الإنتاجية في المرسل، ثيريس الإنتاجية في المتلقي، ثيريس الإنتاجية في أي نقطة وسيطة بين اثنين، ولكن ثيريس لا شيء مثل الإنتاجية الإجمالية للنظام بأكمله. والإنتاجية المنطقي فقط لمجموعة من الرسائل ثيريس لا شيء مثل الإنتاجية من رسالة واحدة. أما بالنسبة للعلاقة بين الإنتاجية والكمون، اتضح أن هناك حقا علاقة ولكن، الصيغة تنطوي على تكاملات ونحن لن نناقش هنا. لمزيد من المعلومات، قراءة الأدب على نظرية الطابور. هناك العديد من المزالق في قياس أنظمة المراسلة التي لن نذهب إلى أبعد من ذلك. يجب أن يوضع الضغط على الدرس المستفاد: تأكد من فهم المشكلة التي تحلها. حتى مشكلة بسيطة مثل جعله سريع يمكن أن تأخذ الكثير من العمل لفهم صحيح. ما هو أكثر من ذلك، إذا كنت لا تفهم المشكلة، فمن المحتمل أن تبني افتراضات ضمنية والخرافات الشعبية في التعليمات البرمجية الخاصة بك، مما يجعل الحل إما معيبة أو على الأقل أكثر تعقيدا أو أقل فائدة بكثير مما كان يمكن أن يكون. 24.4. المسار الحرج اكتشفنا خلال عملية التحسين أن ثلاثة عوامل لها تأثير حاسم على الأداء: عدد تخصيصات الذاكرة عدد مكالمات النظام نموذج التزامن ومع ذلك، ليس كل تخصيص الذاكرة أو كل استدعاء النظام له نفس التأثير على الأداء. إن الأداء الذي نهتم به في أنظمة الرسائل هو عدد الرسائل التي يمكننا نقلها بين نقطتين نهائيتين خلال فترة معينة من الوقت. بدلا من ذلك، قد نكون مهتمين في الوقت الذي يستغرقه وصول رسالة من نقطة نهاية إلى أخرى. ومع ذلك، وبالنظر إلى أن أوسلاشمق مصمم للسيناريوهات مع اتصالات طويلة العمر، والوقت الذي يستغرقه لإقامة اتصال أو الوقت اللازم لمعالجة خطأ اتصال غير ذي صلة في الأساس. هذه الأحداث تحدث نادرا جدا، وبالتالي فإن تأثيرها على الأداء العام لا يكاد يذكر. الجزء من كودباس التي يتم استخدامها بشكل متكرر جدا، مرارا وتكرارا، ويسمى الأمثل المسار الحرجة ينبغي أن تركز على المسار الحرج. دعونا نلقي نظرة على مثال: أوسلاشمق ليست الأمثل للغاية فيما يتعلق بتخصيصات الذاكرة. على سبيل المثال، عند التلاعب بالسلاسل، فإنه غالبا ما يخصص سلسلة جديدة لكل مرحلة وسيطة من التحول. ومع ذلك، إذا نظرنا بدقة في باثمداشث الحرجة رسالة الفعلية باسينغمداشويل معرفة أنه يستخدم تقريبا أي تخصيصات الذاكرة. إذا كانت الرسائل صغيرة، تخصيص الذاكرة واحد فقط لكل 256 رسائل (يتم الاحتفاظ بهذه الرسائل في واحد كبير تخصيص الذاكرة قطعة). إذا، بالإضافة إلى ذلك، تيار الرسائل ثابت، دون قمم حركة المرور الضخمة، وعدد من تخصيصات الذاكرة على المسار الحرج قطرات إلى الصفر (لا يتم إرجاع قطع الذاكرة المخصصة إلى النظام، ولكن إعادة استخدامها مرارا وتكرارا) . الدرس المستفاد: تحسين حيث يجعل الفرق. تحسين أجزاء من التعليمات البرمجية التي ليست على المسار الحرج هو الجهد الضائع. 24.5. تخصيص الذاكرة على افتراض أن جميع البنية التحتية تم إنيتياليزد وتم إنشاء اتصال بين نقطتين نهاية، ثيريس شيء واحد فقط لتخصيص عند إرسال رسالة: الرسالة نفسها. وهكذا، لتحسين المسار الحرج كان علينا أن ننظر في كيفية تخصيص الرسائل وتمرير صعودا وهبوطا المكدس. المعرفة المشتركة في مجال الشبكات عالية الأداء أن أفضل أداء يتحقق من خلال موازنة بعناية تكلفة توزيع الرسالة وتكلفة نسخ الرسالة (على سبيل المثال، hal. inria. frdocs00292831PDFOpen-مكس-IOAT. pdf انظر التعامل مع مختلف الرسائل الصغيرة والمتوسطة والكبيرة). للرسائل الصغيرة، والنسخ هو أرخص بكثير من تخصيص الذاكرة. ومن المنطقي تخصيص أي قطع الذاكرة الجديدة على الإطلاق، وبدلا من ذلك لنسخ الرسالة إلى الذاكرة بريالوكاتد كلما دعت الحاجة. بالنسبة للرسائل الكبيرة، من ناحية أخرى، النسخ هو أكثر تكلفة بكثير من تخصيص الذاكرة. من المنطقي تخصيص الرسالة مرة واحدة وتمرير مؤشر إلى الكتلة المخصصة بدلا من نسخ البيانات. ويسمى هذا النهج صفر نسخة. أوسلاشمق يعالج كلتا الحالتين بطريقة شفافة. تم تمثيل رسالة أوسلاشمق بمعالجة غير شفافة. يتم ترميز محتوى الرسائل الصغيرة جدا مباشرة في المقبض. لذلك فإن نسخ نسخة من المقبض ينسخ بيانات الرسالة. عندما تكون الرسالة أكبر، يتم تخصيصها في مخزن منفصل والمقبض يحتوي فقط على مؤشر إلى المخزن المؤقت. جعل نسخة من المقبض لا يؤدي إلى نسخ بيانات الرسالة، وهو أمر منطقي عندما تكون الرسالة طويلة ميغابايت (الشكل 24.3). وتجدر الإشارة إلى أنه في الحالة الأخيرة يتم حساب المخزن المؤقت للإشارة بحيث يمكن الرجوع إليه بواسطة مقابض متعددة دون الحاجة لنسخ البيانات. الدرس المستفادة: عند التفكير في الأداء، لا تفترض ثيريس أفضل حل واحد. قد يحدث أن هناك عدة فئات فرعية للمشكلة (مثل الرسائل الصغيرة مقابل الرسائل الكبيرة)، ولكل منها خوارزمية مثالية. 24.6. الخلط وقد سبق ذكره أن العدد الهائل من نظام يدعو في نظام الرسائل يمكن أن يؤدي إلى عنق الزجاجة الأداء. في الواقع، المشكلة أكثر عمومية من ذلك بكثير. هي عقوبة الأداء غير تافهة المرتبطة اجتياز كومة المكالمة، وبالتالي، عند إنشاء تطبيقات عالية الأداء، من الحكمة لتجنب أكبر قدر من كومة عبور ممكن. انظر الشكل 24.4. لإرسال أربع رسائل، يجب اجتياز كومة الشبكة بالكامل أربع مرات (أي أوسلاشمق، غليبك، حدود مساحة المستخدم، تنفيذ تكب، تنفيذ إب، طبقة إيثرنيت، نيك نفسه ونسخ المكدس مرة أخرى). ومع ذلك، إذا قررت الانضمام إلى تلك الرسائل في دفعة واحدة، سيكون هناك اجتياز واحد فقط من المكدس (الشكل 24.5). يمكن أن يكون التأثير على إنتاجية الرسائل ساحقا: يصل إلى أمرين من حيث الحجم، خاصة إذا كانت الرسائل صغيرة ومئات منها يمكن أن تكون معبأة في دفعة واحدة. من ناحية أخرى، يمكن أن يكون للخلط تأثير سلبي على زمن الاستجابة. دعونا نأخذ، على سبيل المثال، خوارزمية ناجليز المعروفة، كما تم تنفيذها في برنامج التعاون الفني. فإنه يؤخر الرسائل الصادرة لفترة معينة من الزمن ويدمج جميع البيانات المتراكمة في حزمة واحدة. ومن الواضح أن زمن الاستجابة من البداية إلى النهاية للرسالة الأولى في الرزمة أسوأ بكثير من زمن الكمون الأخير. وهكذا، المشتركة ل التطبيقات التي تحتاج باستمرار الكمون المنخفض للتبديل ناجليز خوارزمية قبالة. حتى المشتركة لإيقاف الخلط على جميع المستويات من المكدس (على سبيل المثال نيك يقاطع ميزة التجميع). ولكن مرة أخرى، لا الخلط يعني اجتياز واسعة من المكدس والنتائج في انخفاض الإنتاجية الرسالة. يبدو أننا اشتعلت في الإنتاجية مقابل معضلة الكمون. يحاول أوسلاشمق تقديم حالات تأخر منخفضة باستمرار جنبا إلى جنب مع الإنتاجية العالية باستخدام الاستراتيجية التالية: عندما تدفق الرسالة هو متفرق ولا تتجاوز شبكة مداخن عرض النطاق الترددي، أوسلاشمق يتحول كل الخلط قبالة لتحسين الكمون. المفاضلة هنا أعلى إلى حد ما وحدة المعالجة المركزية أوساجيمداشو لا يزال لديك لاجتياز كومة في كثير من الأحيان. ومع ذلك، لا يعتبر ذلك مشكلة في معظم الحالات. عندما يتجاوز معدل الرسالة عرض النطاق الترددي من كومة الشبكة، يجب أن تكون الرسائل كويدمداشوريد في الذاكرة حتى كومة جاهزة لقبول لهم. الطابور يعني الكمون هو الذهاب الى النمو. إذا كانت الرسالة تنفق ثانية واحدة في قائمة الانتظار، فإن زمن الاستجابة من طرف إلى طرف سيكون ثانية واحدة على الأقل. ما هو أسوأ من ذلك، كما ينمو حجم طابور، وسوف تزيد من حالات التأخير تدريجيا. If the size of the queue is not bound, the latency can exceed any limit. It has been observed that even though the network stack is tuned for lowest possible latency (Nagles algorithm switched off, NIC interrupt coalescing turned off, etc.) latencies can still be dismal because of the queueing effect, as described above. In such situations it makes sense to start batching aggressively. Theres nothing to lose as the latencies are already high anyway. On the other hand, aggressive batching improves throughput and can empty the queue of pending messagesmdashwhich in turn means the latency will gradually drop as the queueing delay decreases. Once there are no outstanding messages in the queue, the batching can be turned off to improve the latency even further. One additional observation is that the batching should only be done on the topmost level. If the messages are batched there, the lower layers have nothing to batch anyway, and so all the batching algorithms underneath do nothing except introduce additional latency. Lesson learned: To get optimal throughput combined with optimal response time in an asynchronous system, turn off all the batching algorithms on the low layers of the stack and batch on the topmost level. Batch only when new data are arriving faster than they can be processed. 24.7. Architecture Overview Up to this point we have focused on generic principles that make OslashMQ fast. From now on well have a look at the actual architecture of the system (Figure 24.6 ). The user interacts with OslashMQ using so-called sockets. They are pretty similar to TCP sockets, the main difference being that each socket can handle communication with multiple peers, a bit like unbound UDP sockets do. The socket object lives in the users thread (see the discussion of threading models in the next section). Aside from that, OslashMQ is running multiple worker threads that handle the asynchronous part of the communication: reading data from the network, enqueueing messages, accepting incoming connections, etc. There are various objects living in the worker threads. Each of these objects is owned by exactly one parent object (ownership is denoted by a simple full line in the diagram). The parent can live in a different thread than the child. Most objects are owned directly by sockets however, there are couple of cases where an object is owned by an object which is owned by the socket. What we get is a tree of objects, with one such tree per socket. The tree is used during shut down no object can shut itself down until it closes all its children. This way we can ensure that the shut down process works as expected for example, that pending outbound messages are pushed to the network prior to terminating the sending process. Roughly speaking, there are two kinds of asynchronous objects there are objects that are not involved in message passing and there are objects that are. The former have to do mainly with connection management. For example, a TCP listener object listens for incoming TCP connections and creates an enginesession object for each new connection. Similarly, a TCP connector object tries to connect to the TCP peer and when it succeeds it creates an enginesession object to manage the connection. When such connection fails, the connector object tries to re-establish it. The latter are objects that are handling data transfer itself. These objects are composed of two parts: the session object is responsible for interacting with the OslashMQ socket, and the engine object is responsible for communication with the network. Theres only one kind of the session object, but theres a different engine type for each underlying protocol OslashMQ supports. Thus, we have TCP engines, IPC (inter-process communication) engines, PGM engines (a reliable multicast protocol, see RFC 3208), etc. The set of engines is extensiblemdashin the future we may choose to implement, say, a WebSocket engine or an SCTP engine. The sessions are exchanging messages with the sockets. There are two directions to pass messages in and each direction is handled by a pipe object. Each pipe is basically a lock-free queue optimized for fast passing of messages between threads. Finally, theres a context object (discussed in the previous sections but not shown on the diagram) that holds the global state and is accessible by all the sockets and all the asynchronous objects. 24.8. Concurrency Model One of the requirements for OslashMQ was to take advantage of multi-core boxes in other words, to scale the throughput linearly with the number of available CPU cores. Our previous experience with messaging systems showed that using multiple threads in a classic way (critical sections, semaphores, etc.) doesnt yield much performance improvement. In fact, a multi-threaded version of a messaging system can be slower than a single-threaded one, even if measured on a multi-core box. Individual threads are simply spending too much time waiting for each other while, at the same time, eliciting a lot of context switching that slows the system down. Given these problems, weve decided to go for a different model. The goal was to avoid locking entirely and let each thread run at full speed. The communication between threads was to be provided via asynchronous messages (events) passed between the threads. This, as insiders know, is the classic actor model . The idea was to launch one worker thread per CPU coremdashhaving two threads sharing the same core would only mean a lot of context switching for no particular advantage. Each internal OslashMQ object, such as say, a TCP engine, would be tightly bound to a particular worker thread. That, in turn, means that theres no need for critical sections, mutexes, semaphores and the like. Additionally, these OslashMQ objects wont be migrated between CPU cores so would thus avoid the negative performance impact of cache pollution (Figure 24.7 ). This design makes a lot of traditional multi-threading problems disappear. Nevertheless, theres a need to share the worker thread among many objects, which in turn means there has to be some kind of cooperative multitasking. This means we need a scheduler objects need to be event-driven rather than being in control of the entire event loop we have to take care of arbitrary sequences of events, even very rare ones we have to make sure that no object holds the CPU for too long etc. In short, the whole system has to become fully asynchronous. No object can afford to do a blocking operation, because it would not only block itself but also all the other objects sharing the same worker thread. All objects have to become, whether explicitly or implicitly, state machines. With hundreds or thousands of state machines running in parallel you have to take care of all the possible interactions between them andmdashmost importantlymdashof the shutdown process. It turns out that shutting down a fully asynchronous system in a clean way is a dauntingly complex task. Trying to shut down a thousand moving parts, some of them working, some idle, some in the process of being initiated, some of them already shutting down by themselves, is prone to all kinds of race conditions, resource leaks and similar. The shutdown subsystem is definitely the most complex part of OslashMQ. A quick check of the bug tracker indicates that some 30--50 of reported bugs are related to shutdown in one way or another. Lesson learned: When striving for extreme performance and scalability, consider the actor model its almost the only game in town in such cases. However, if you are not using a specialised system like Erlang or OslashMQ itself, youll have to write and debug a lot of infrastructure by hand. Additionally, think, from the very beginning, about the procedure to shut down the system. Its going to be the most complex part of the codebase and if you have no clear idea how to implement it, you should probably reconsider using the actor model in the first place. 24.9. Lock-Free Algorithms Lock-free algorithms have been in vogue lately. They are simple mechanisms for inter-thread communication that dont rely on the kernel-provided synchronisation primitives, such as mutexes or semaphores rather, they do the synchronisation using atomic CPU operations, such as atomic compare-and-swap (CAS). It should be understood that they are not literally lock-freemdashinstead, locking is done behind the scenes on the hardware level. OslashMQ uses a lock-free queue in pipe objects to pass messages between the users threads and OslashMQs worker threads. There are two interesting aspects to how OslashMQ uses the lock-free queue. First, each queue has exactly one writer thread and exactly one reader thread. If theres a need for 1-to - N communication, multiple queues are created (Figure 24.8 ). Given that this way the queue doesnt have to take care of synchronising the writers (theres only one writer) or readers (theres only one reader) it can be implemented in an extra-efficient way. Second, we realised that while lock-free algorithms were more efficient than classic mutex-based algorithms, atomic CPU operations are still rather expensive (especially when theres contention between CPU cores) and doing an atomic operation for each message written andor each message read was slower than we were willing to accept. The way to speed it upmdashonce againmdashwas batching. Imagine you had 10 messages to be written to the queue. It can happen, for example, when you received a network packet containing 10 small messages. Receiving a packet is an atomic event you cannot get half of it. This atomic event results in the need to write 10 messages to the lock-free queue. Theres not much point in doing an atomic operation for each message. Instead, you can accumulate the messages in a pre-write portion of the queue thats accessed solely by the writer thread, and then flush it using a single atomic operation. The same applies to reading from the queue. Imagine the 10 messages above were already flushed to the queue. The reader thread can extract each message from the queue using an atomic operation. However, its overkill instead, it can move all the pending messages to a pre-read portion of the queue using a single atomic operation. Afterwards, it can retrieve the messages from the pre-read buffer one by one. Pre-read is owned and accessed solely by the reader thread and thus no synchronisation whatsoever is needed in that phase. The arrow on the left of Figure 24.9 shows how the pre-write buffer can be flushed to the queue simply by modifying a single pointer. The arrow on the right shows how the whole content of the queue can be shifted to the pre-read by doing nothing but modifying another pointer. Lesson learned: Lock-free algorithms are hard to invent, troublesome to implement and almost impossible to debug. If at all possible, use an existing proven algorithm rather than inventing your own. When extreme performance is required, dont rely solely on lock-free algorithms. While they are fast, the performance can be significantly improved by doing smart batching on top of them. 24.10. API The user interface is the most important part of any product. Its the only part of your program visible to the outside world and if you get it wrong the world will hate you. In end-user products its either the GUI or the command line interface. In libraries its the API. In early versions of OslashMQ the API was based on AMQPs model of exchanges and queues. (See the AMQP specification .) From a historical perspective its interesting to have a look at the white paper from 2007 that tries to reconcile AMQP with a brokerless model of messaging. I spent the end of 2009 rewriting it almost from scratch to use the BSD Socket API instead. That was the turning point OslashMQ adoption soared from that point on. While before it was a niche product used by a bunch of messaging experts, afterwards it became a handy commonplace tool for anybody. In a year or so the size of the community increased tenfold, some 20 bindings to different languages were implemented, etc. The user interface defines the perception of a product. With basically no change to the functionalitymdashjust by changing the APImdashOslashMQ changed from an enterprise messaging product to a networking product. In other words, the perception changed from a complex piece of infrastructure for big banks to hey, this helps me to send my 10-byte-long message from application A to application B. Lesson learned: Understand what you want your project to be and design the user interface accordingly. Having a user interface that doesnt align with the vision of the project is a 100 guaranteed way to fail. One of the important aspects of the move to the BSD Sockets API was that it wasnt a revolutionary freshly invented API, but an existing and well-known one. Actually, the BSD Sockets API is one of the oldest APIs still in active use today it dates back to 1983 and 4.2BSD Unix. Its been widely used and stable for literally decades. The above fact brings a lot of advantages. Firstly, its an API that everybody knows, so the learning curve is ludicrously flat. Even if youve never heard of OslashMQ, you can build your first application in couple of minutes thanks to the fact that you are able to reuse your BSD Sockets knowledge. Secondly, using a widely implemented API enables integration of OslashMQ with existing technologies. For example, exposing OslashMQ objects as sockets or file descriptors allows for processing TCP, UDP, pipe, file and OslashMQ events in the same event loop. Another example: the experimental project to bring OslashMQ-like functionality to the Linux kernel turned out to be pretty simple to implement. By sharing the same conceptual framework it can re-use a lot of infrastructure already in place. Thirdly and probably most importantly, the fact that the BSD Sockets API survived almost three decades despite numerous attempts to replace it means that there is something inherently right in the design. BSD Sockets API designers havemdashwhether deliberately or by chancemdashmade the right design decisions. By adopting the API we can automatically share those design decisions without even knowing what they were and what problem they were solving. Lesson learned: While code reuse has been promoted from time immemorial and pattern reuse joined in later on, its important to think of reuse in an even more generic way. When designing a product, have a look at similar products. Check which have failed and which have succeeded learn from the successful projects. Dont succumb to Not Invented Here syndrome. Reuse the ideas, the APIs, the conceptual frameworks, whatever you find appropriate. By doing so you are allowing users to reuse their existing knowledge. At the same time you may be avoiding technical pitfalls you are not even aware of at the moment. 24.11. Messaging Patterns In any messaging system, the most important design problem is that of how to provide a way for the user to specify which messages are routed to which destinations. There are two main approaches, and I believe this dichotomy is quite generic and applicable to basically any problem encountered in the domain of software. One approach is to adopt the Unix philosophy of do one thing and do it well. What this means is that the problem domain should be artificially restricted to a small and well-understood area. The program should then solve this restricted problem in a correct and exhaustive way. An example of such approach in the messaging area is MQTT. Its a protocol for distributing messages to a set of consumers. It cant be used for anything else (say for RPC) but it is easy to use and does message distribution well. The other approach is to focus on generality and provide a powerful and highly configurable system. AMQP is an example of such a system. Its model of queues and exchanges provides the user with the means to programmatically define almost any routing algorithm they can think of. The trade-off, of course, is a lot of options to take care of. OslashMQ opts for the former model because it allows the resulting product to be used by basically anyone, while the generic model requires messaging experts to use it. To demonstrate the point, lets have a look how the model affects the complexity of the API. What follows is implementation of RPC client on top of a generic system (AMQP): On the other hand, OslashMQ splits the messaging landscape into so-called messaging patterns. Examples of the patterns are publishsubscribe, requestreply or parallelised pipeline. Each messaging pattern is completely orthogonal to other patterns and can be thought of as a separate tool. What follows is the re-implementation of the above application using OslashMQs requestreply pattern. Note how all the option tweaking is reduced to the single step of choosing the right messaging pattern ( REQ ): Up to this point weve argued that specific solutions are better than generic solutions. We want our solution to be as specific as possible. However, at the same time we want to provide our customers with as wide a range of functionality as possible. How can we solve this apparent contradiction The answer consists of two steps: Define a layer of the stack to deal with a particular problem area (e. g. transport, routing, presentation, etc.). Provide multiple implementations of the layer. There should be a separate non-intersecting implementation for each use case. Lets have a look at the example of the transport layer in the Internet stack. Its meant to provide services such as transferring data streams, applying flow control, providing reliability, etc. on the top of the network layer (IP). It does so by defining multiple non-intersecting solutions: TCP for connection-oriented reliable stream transfer, UDP for connectionless unreliable packet transfer, SCTP for transfer of multiple streams, DCCP for unreliable connections and so on. Note that each implementation is completely orthogonal: a UDP endpoint cannot speak to a TCP endpoint. Neither can a SCTP endpoint speak to a DCCP endpoint. It means that new implementations can be added to the stack at any moment without affecting the existing portions of the stack. Conversely, failed implementations can be forgotten and discarded without compromising the viability of the transport layer as a whole. The same principle applies to messaging patterns as defined by OslashMQ. Messaging patterns form a layer (the so-called scalability layer) on top of the transport layer (TCP and friends). Individual messaging patterns are implementations of this layer. They are strictly orthogonalmdashthe publishsubscribe endpoint cant speak to the requestreply endpoint, etc. Strict separation between the patterns in turn means that new patterns can be added as needed and that failed experiments with new patterns wont hurt the existing patterns. Lesson learned: When solving a complex and multi-faceted problem it may turn out that a monolithic general-purpose solution may not be the best way to go. Instead, we can think of the problem area as an abstract layer and provide multiple implementations of this layer, each focused on a specific well-defined use case. When doing so, delineate the use case carefully. Be sure about what is in the scope and what is not. By restricting the use case too aggressively the application of your software may be limited. If you define the problem too broadly, however, the product may become too complex, blurry and confusing for the users. 24.12. Conclusion As our world becomes populated with lots of small computers connected via the Internetmdashmobile phones, RFID readers, tablets and laptops, GPS devices, etc. mdashthe problem of distributed computing ceases to be the domain of academic science and becomes a common everyday problem for every developer to tackle. The solutions, unfortunately, are mostly domain-specific hacks. This article summarises our experience with building a large-scale distributed system in a systematic manner. It focuses on problems that are interesting from a software architecture point of view, and we hope that designers and programmers in the open source community will find it useful. Back to top Back to The Architecture of Open Source Applications. WARNING: This text is deprecated and refers to an old version of MQ. It remains here for historical interest. DO NOT USE THIS TO LEARN MQ. Introduction As MQ is primarily intended to power stock trading business, weve created an sample application that simulates internal working of a stock exchange. The primary focus of this example is to show how MQ perfroms in real-world-like scenario. The diagram below shows the architecture of the application: Gateway component should get orders from traders over the network (using FIX protocol or a specific proprietary protocol) and send replies back to the traders. However, as the example application is intended to show what are the possible throughputslatencies of such a system, gateway generates random orders instead of receiving them from the traders. When starting the gateway, you can specify number of orders per second to be generated. Matching unit contains the core of stock exchange business logic. It matches orders one to another and produces trades and quotes. Our implementation is minimalistic, based on timeprice matching algorithm (implementing pro rata algorithm is left as an excercise for the reader). Still, the algorithm has complexity of O(1) and it is heavily optimised. Weve seen it process some 18 million orders per second. Statistics component receives performance info generated by both gateway and matching engine and displays it in human-readable form. To make reading of statistics even more convenient, simple graphical tool is included in the example. Performance Following screenshot shows examples performance on two high-end 8-core (3GHz) boxes each having 2 dedicated 1GbE NICs. Keep in mind that if you run it on the underspecified andor untuned hardware it can be still pretty fast, however, youll experience lower message throughputs and more latency peaks. If you set the message rate too high you can even experience gatway failure as the ticker component used to send orders at the stable rate wont be able to keep pace. The yellow line shows roundtrip latency, i. e. how long it took to pass the order from the gateway to the matching engine, process it and send order confirmation back to the gateway. In our test latency fluctuated around 200 microsecond average. The lower throughput line (900,000 messagessecond) is the rate of orders being passed from the gateway to the matching engine. The upper throughput line (2,300,000 messagessecond) is the rate of order confirmations, trades and stock quotes passed from the matching engine to the gateway. In total, weve seen approximately 3,200,000 messages per second passing through the network. Building it To build the example use --with-exchange option with configure: To be able to run the graphing tool you have to have Perl-Tk installed (packaged as perl-tk on Debian) as well as Tk::Graph from CPAN. Running it For example, we have following network topology to run the example on. Boxes represent individual machines, arrows represent physical cables between individual network interfaces (marked by their respective IP addresses): There are 3 boxes (test01, test02 and test03) connected to the switched network with respective IP addresses of 192.168.0.1, 192.168.0.2 and 192.168.0.3. Moreover there are two direct connections between test02 and test03. One connection connects network interface 10.0.0.1 on test02 with network interface 10.0.0.2 on test03. Other one connectes network interface 10.1.0.1 on test02 with network interface 10.1.0.2 on test03. Well run zmqserver and statistical component on test01, matching engine on test02 and gateway on test03. Well use one of the direct connections between test02 and test03 to pass orders from gatway to matching engine and the other one to pass confirmations, trades and quotes from matching engine to gateway. First, start zmqserver on test01: Afterwards start the statistical component on test01. The parameters are the box where zmqserver is running and network interface to receive statistical info on: Alternatively you can pipe the statistical data to the graphing tool: Now start the matching engine. Supply zmqserver s host name, interface to receive messages on and interface to send messages on as parameters: Finally, run the gatway. Supply location of zmqserver and the number of orders to send per second as parameters: Conclusion Exchange example allows you to test MQs performance in real-world-like scenario. However, getting stable latency at high throughputs is a tricky matter dependent on overall tuning of your hardware, operating system, execution environment etc. If you are serious about performance testing, contact us to help you with the task. Written: 1218019882Y. m.e Revised: 1286694428Y. m.e If you found this page useful, please rate it up so others will find it.
No comments:
Post a Comment