'We use Apache Ignite in everyday life'

Data terabytes, clusters for hundreds of machines, big data, high load, machine learning, microservices... and other scary words are all applicable to Apache® Ignite™. But this does not mean that it is not suitable for less ambitious goals.

Today, we'll look at how Ignite can easily store any of your objects, share them over the network, and provide .NET and Java interoperability.

Today, we'll look at how Ignite can easily store any of your objects, share them over the network, and provide .NET and Java interoperability
We will talk more about the .NET API, but some things are also applicable in Java.

Embedded Database

Ignite does not require installation and configuration, it can be started right in your process, and since version 2.1 it can store data on disk . Add to this a fast and compact built-in serialization and get the easiest way to save any of your objects to disk.
var cfg = new IgniteConfiguration
{
    // Ignite persistence configuration.
    PersistentStoreConfiguration = new PersistentStoreConfiguration()
};

var ignite = Ignition.Start(cfg);
ignite.SetActive(true);  // Explicit cluster activation required if the persistence is on.
var cache = ignite.GetOrCreateCache<int, MyClass>("foo");
cache[cache.GetSize() + 1] = new MyClass();

 
That's all the code! We start several times and make sure that the data is not lost.

At the same time, MyClassno demands are made! It can be anything, any nesting, including delegates, anonymous types and methods, expression trees, dynamic objects, and so on. Can your serializer do this? I do not think so. The only exception is that you can not do it IntPtr, but it's for your own good. Serializing pointers is a bad idea.

Moreover, serialized objects are not a "black box", IBinaryObject allows you to selectively receive and modify individual fields of objects.

Of course, you can work with all these data in both key-value ( ICache.Put, ICache.Get) mode , and through SQL , LINQ , full-text search.

Note that, in addition to the embedded mode, Ignite can work through ODBC and JDBC.

Interprocess communication

The Google Chrome browser uses a separate process for each tab. Implementing this approach with Ignite is very simple: data can be easily and transparently exchanged through the cache, synchronize code execution through distributed data structures, and exchange messages via Messaging.

Processes can be equal. For example, the navigation history can be stored in the Replicated-cache, so that each tab when updating the link updates the history, can read it, and the fall of one of the processes does not affect the data safety. In the code, this all just looks like working with a collection.

var history = ignite.GetCache<Guid, HistoryItem>("history");
history.Put(Guid.NewGuid(), new HistoryItem(url, DateTime.UtcNow));

// Show the 10 latest visited pages.
history.AsCacheQueryable()
          .Select(x => x.Value)
          .OrderByDescending(x => x.Date)
          .Take(10);

 
Ignite provides thread-safe access to data within the entire cluster.

Cross-platform interaction

In Ignite there are full-fledged APIs in Java, .NET, C ++. You can start on Windows, Linux, Mac. For example, part of your application can be written in Java and running on Linux, another part - on .NET and under Windows.

The serialization protocol is universal, objects written on one platform can be read to another. The data structures mentioned above are also cross-platform.

Moreover, it is possible to transparently invoke .NET services written in Java, as follows:

public class MyJavaService implements Service {
  public String sayHello(String x) {
    return "Hello, " + x;
  }
}

ignite.services().deployClusterSingleton("myJavaSvc", new MyJavaService());
 
interface IJavaService  // Custom Service name.
{
  string sayHello(string str); 
}

var prx = ignite.GetServices().GetServiceProxy<IJavaService>("myJavaSvc");
string result = prx.sayHello("Vasya");  
 

As everywhere, you can transfer any objects instead of rows.

 

A detailed guide to building a cross-platform Ignite cluster, using the example of a simple chat room, is here.

Conclusion  

Ignite does work with any data quickly and pleasantly: serialize, store in memory or on disk, transfer over the network, ensure consistency and thread safety. Even the smallest projects can benefit from the product, without worrying about the possible increase in the load in the future.

Share This