كيفية تحميل جدول كبير بسرعة في Apache Ignite عبر Key-Value API

منذ بعض الوقت ، ظهرت منصة Apache Ignite في الأفق وبدأت تكتسب شعبية. تتعلق الحوسبة في الذاكرة بالسرعة ، مما يعني أنه يجب ضمان السرعة في جميع مراحل العمل ، خاصة عند تحميل البيانات.



يوجد أسفل القطع وصف لطريقة التحميل السريع للبيانات من جدول علائقي إلى مجموعة Apache Ignite الموزعة. وصفت المعالجة المسبقة لنتائج استعلام SQL المحددة على عقدة العميل الخاصة بالكتلة وتوزيع البيانات عبر الكتلة باستخدام مهمة تقليل الخريطة. يصف ذاكرات التخزين المؤقت والجداول الارتباطية ذات الصلة ، ويوضح كيفية إنشاء كائن مخصص من صف جدول ، وكيفية استخدام ComputeTaskAdapter لوضع الكائنات التي تم إنشاؤها بسرعة. يمكن رؤية كل الكود بالكامل في مستودع FastDataLoad .



تاريخ القضية



هذا النص هو ترجمة إلى اللغة الروسية من بلدي آخر في المدونة في الذاكرة الحاسبات على موقع GridGain.



لذلك ، قررت شركة معينة تسريع تطبيق بطيء عن طريق نقل الحوسبة إلى كتلة داخل الذاكرة. البيانات الأولية للحسابات في MS SQL ؛ يجب وضع نتيجة الحسابات هناك. يتم توزيع الكتلة ، نظرًا لوجود الكثير من البيانات بالفعل ، فإن أداء التطبيق عند الحد الأقصى وحجم البيانات ينمو. يتم تعيين حدود الوقت الصعب.



قبل كتابة رمز سريع لمعالجة البيانات ، يجب تحميل البيانات بسرعة. يكشف البحث المحموم على الويب عن ندرة واضحة في أمثلة التعليمات البرمجية التي يمكن توسيع نطاقها إلى جداول من عشرات أو مئات الملايين من الصفوف. أمثلة يمكنك تنزيلها وتجميعها والمتابعة عبر خطوات تصحيح الأخطاء. هذا من جهة.



من ناحية أخرى ، تعطي وثائق Apache Ignite / GridGain والندوات عبر الإنترنت والاجتماعات فكرة عن الهيكل الداخلي للمجموعة. من خلال التجربة والخطأ ، من الممكن إنشاء أداة تحميل تأخذ في الاعتبار توزيع البيانات عبر الأقسام. وعندما تسأل السلطات ذات يوم "هل لعب آصك الرابح؟" ، الإجابة هي نعم ، كل شيء سار على ما يرام.

يبدو أن الكود الناتج هو نوع من المنتجات محلية الصنع بلمسة من العمارة الداخلية ، ولكنه يعمل بسرعة كافية.



تنزيل البيانات (قاعدة البيانات العالمية)



, data collocation, . world.sql Apache Ignite.



CSV , — SQL :





countryCache country.csv. countryCache — code, — String, — Country, (name, continent, region).







, — , . Country , . org.h2.tools.Csv, CSV java.sql.ResultSet. Apache Ignite , SQL H2.



    // define countryCache
    IgniteCache<String,Country> cache = ignite.cache("countryCache");

    try (ResultSet rs = new Csv().read(csvFileName, null, null)) {
     while (rs.next()) {
      String code = rs.getString("Code");
      String name = rs.getString("Name");
      String continent = rs.getString("Continent");
      Country country = new Country(code,name,continent);
      cache.put(code,country);
     }
    }


. , , . - .



, . , .





Apache Ignite — -. , PARTITIONED - (partition) . ; , . -, affinity function, , .



ResultSet . , . .





, :



  • HashMap partition_number -> key -> Value

    Map<Integer, Map<String, Country>> result = new HashMap<>();
  • affinity function partition_number. cache.put() - HashMap partition_number

    try (ResultSet rs = new Csv().read(csvFileName, null, null)) {
     while (rs.next()) {
      String code = rs.getString("Code");
      String name = rs.getString("Name");
      String continent = rs.getString("Continent");
      Country country = new Country(code,name,continent);
      result.computeIfAbsent(affinity.partition(key), k -> new HashMap<>()).put(code,country);
     }
    }


ComputeTaskAdapter ComputeJobAdapter. ComputeJobAdapter 1024. , .



ComputeJobAdapter . , .



Compute Task,



, "ComputeTaskAdapter initiates the simplified, in-memory, map-reduce process". ComputeJobAdapter map — , . reduce — .



(RenewLocalCacheJob)



, RenewLocalCacheJob .



targetCache.putAll(addend);


RenewLocalCacheJob partition_number .



(AbstractLoadTask)



( loader) — AbstractLoadTask. . ( ), AbstractLoadTask TargetCacheKeyType. HashMap



    Map<Integer, Map<TargetCacheKeyType, BinaryObject>> result;


countryCache String. . AbstractLoadTask TargetCacheKeyType, BinaryObject. , — .



BinaryObject



— . , JVM, - . class definition , JAR- . Country



    IgniteCache<String, Country> countryCache;


, , classpath ClassNotFound.



. — classpath, :



  • JAR- ;
  • classpath ;
  • ;
  • .


BinaryObject () . :





  • IgniteCache<String, BinaryObject> countryCache;    
  • Country BinaryObject (. LoadCountries.java)

    Country country = new Country(code, name, .. );    
    BinaryObject binCountry = node.binary().toBinary(country);    
  • HashMap, BinaryObject

    Map<Integer, Map<String, BinaryObject>> result


, . , , ClassNotFoundException .



. .



Apache Ignite : .





default-config.xml — . :



  • GridGain CE Installing Using ZIP Archive. 8.7.10, FastDataLoad , ;
  • {gridgain}\config default-config.xml



    <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="peerClassLoadingEnabled" value="true"/>
    </bean>
  • , {gridgain}\bin ignite.bat. ; ;
  • , . ,

    [08:40:04] Topology snapshot [ver=2, locNode=d52b1db3, servers=2, clients=0, state=ACTIVE, CPUs=8, offheap=3.2GB, heap=2.0GB]


. , 8.7.25, pom.xml



    <gridgain.version>8.7.25</gridgain.version>




class org.apache.ignite.spi.IgniteSpiException: Local node and remote node have different version numbers (node will not join, Ignite does not support rolling updates, so versions must be exactly the same) [locBuildVer=8.7.25, rmtBuildVer=8.7.10]




, , map-reduce. — JAR-, compute task . Windows, Linux.

:



  • FastDataLoad;
  • ;

    mvn clean package
  • , .

    java -jar .\target\fastDataLoad.jar


main() LoadApp LoaderAgrument . map-reduce LoadCountries.

LoadCountries RenewLocalCacheJob , ( ).



#1





#2









country.csv , CountryCode . cityCache countryLanguageCache; , .





.



.



:



  • (SQL Server Management Studio):

    • — 44 686 837;
    • — 1.071 GB;
  • — 0H:1M:35S;
  • RenewLocalCacheJob reduce — 0H:0M:9S.


يستغرق توزيع البيانات عبر كتلة وقتًا أقل من تنفيذ استعلام SQL.




All Articles