أعجوبة

البرمجيات الحُرة والمفتوحة المصدر

أدوات المستخدم

أدوات الموقع


thawab-pri:concurrency

مشاكل التزامن

في صفحة تطبيق الويب تحدثنا عن تصميم تطبيق الويب.

لكن هناك تحد أساسي غير محصور بتطبيق الويب لكن تطبيق الويب هو الذي ركز النظر عليه وهو مسألة Concurrency

في تطبيق عارض

المشكلة

ظهرت المشكلة لاول مرة عند استعمال خادم paste في تطبيق الويب

  File "Thawab/core.py", line 382, in getSliceBoundary
r=self.__c.execute(SQL_GET_GLOBAL_ORDER,(nodeIdNum,)).fetchone()
ProgrammingError: SQLite objects created in a thread can only be used in
that same thread.The object was created in thread id -1245709456 and this
is thread id -1258292368

تقول sqlite FAQ ويقول هذا الرابط أن الإصدارات الحديثة من sqlite تسمح فتح الاتصال في thread واستعماله في واحد آخر لكن ليس ال cursor

The restriction on moving database connections across threads was relaxed somewhat in version 3.3.1.
With that and subsequent versions, it is safe to move a connection handle across threads
as long as the connection is not holding any fcntl() locks.
You can safely assume that no locks are being held if no transaction is pending and all statements have been finalized.
FWIW: Later versions of sqlite claim you can share connections and objects across threads (except **cursors**),
but I've found otherwise in actual practice.

لكن يبدو أن كلمة statements تشمل عمليات قراءة فقط أو ما شابه.

حيث أنه عندما تم الاستغناء عن كل ال cursors وتم طلب cursor جديد من ال connection حصلنا على

  File "/opt/proj/thawab/Thawab/core.py", line 415, in getSliceBoundary
    r=self.cn.execute(SQL_GET_GLOBAL_ORDER,(nodeIdNum,)).fetchone()
ProgrammingError: SQLite objects created in a thread can only be used in
that same thread.The object was created in thread id -1221371024 and this
is thread id -1289761936

الحل

واحد أو أكثر مما يلي

  • أن نستعمل connection جديد يعني نعمل reconnect بعد استخراج الكائن من الكاش
  • أن نستعمل على الخادم MySql (وطبعا نحتاج الخطوة السابقة أيضا)
  • أن نعمل process واحدة و thread واحد يكون هو مدير الجلسة وهو الذي به كل الاتصالات إلى قاعدة البيانات وتتحدث معه ال threads الأخرى عبر أي وسيلة IPC وربما يمكن استعمال session bus من dbus كما في هجرة
  • أن نستعمل SQLAlchemy (لكن سنخسر عبارات SQL القياسية)
  • أي أفكار أخرى

عند التحرير

ليس ضمن اهتمامنا الآن

لكن تم نقل كل عمليات التحرير وهما Kitab.appendToCurrent و Kitab.dropDecendants لتكون طريقة ل KitabCursor وعملية إنشاء ال Cursor تعمل lock مع أنه الآن مجرد pass.

thawab-pri/concurrency.txt · آخر تعديل: 2015/04/23 03:21 بواسطة 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki