ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject ignite git commit: IGNITE-4125 .NET: Add MultiTieredCacheExample
Date Fri, 18 Nov 2016 10:08:41 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 82e2501ca -> a9715424c


IGNITE-4125 .NET: Add MultiTieredCacheExample

This closes #1234


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a9715424
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a9715424
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a9715424

Branch: refs/heads/master
Commit: a9715424cca459fb04092c292de11377aa728be9
Parents: 82e2501
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Fri Nov 18 13:08:32 2016 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Fri Nov 18 13:08:32 2016 +0300

----------------------------------------------------------------------
 .../Examples/ExamplesTest.cs                    |   5 +-
 .../Apache.Ignite.Examples.csproj               |   1 +
 .../Datagrid/MultiTieredCacheExample.cs         | 136 +++++++++++++++++++
 3 files changed, 140 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a9715424/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
index 112db21..8c017d1 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
@@ -155,8 +155,9 @@ namespace Apache.Ignite.Core.Tests.Examples
         {
             get
             {
-                return Example.GetExamples()
-                    .Where(x => !new[] {"LifecycleExample", "ClientReconnectExample"}.Contains(x.Name));
+                var localOnly = new[] {"LifecycleExample", "ClientReconnectExample", "MultiTieredCacheExample"
};
+
+                return Example.GetExamples().Where(x => !localOnly.Contains(x.Name));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a9715424/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
index 332d3a1..7d0b438 100644
--- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
@@ -52,6 +52,7 @@
     <Compile Include="Compute\TaskExample.cs" />
     <Compile Include="Datagrid\ContinuousQueryExample.cs" />
     <Compile Include="Datagrid\DataStreamerExample.cs" />
+    <Compile Include="Datagrid\MultiTieredCacheExample.cs" />
     <Compile Include="Datagrid\EntryProcessorExample.cs" />
     <Compile Include="Datagrid\NearCacheExample.cs" />
     <Compile Include="Datagrid\OptimisticTransactionExample.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/a9715424/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/MultiTieredCacheExample.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/MultiTieredCacheExample.cs
b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/MultiTieredCacheExample.cs
new file mode 100644
index 0000000..096c743
--- /dev/null
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/MultiTieredCacheExample.cs
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ReSharper disable AssignNullToNotNullAttribute
+namespace Apache.Ignite.Examples.Datagrid
+{
+    using System;
+    using System.IO;
+    using System.Threading;
+    using Apache.Ignite.Core;
+    using Apache.Ignite.Core.Cache;
+    using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Cache.Eviction;
+    using Apache.Ignite.Core.Discovery.Tcp;
+    using Apache.Ignite.Core.Discovery.Tcp.Multicast;
+    using Apache.Ignite.Core.SwapSpace.File;
+
+    /// <summary>
+    /// This example demonstrates on how to configure a multi-tiered Ignite cache that will
store data in different 
+    /// memory spaces (on-heap, off-heap, swap) depending on the total cache size and eviction
policies that are set.
+    /// NOTE: There must be no other cluster nodes running on the host.
+    /// <para />
+    /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click ->
Build).
+    ///    Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration}
folder.
+    /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click
-> Properties ->
+    ///     Application -> Startup object);
+    /// 3) Start example (F5 or Ctrl+F5).
+    /// </summary>
+    public class MultiTieredCacheExample
+    {
+        /// <summary>Example cache name.</summary>
+        private const string CacheName = "dotnet_multi_tiered_example_cache";
+
+        /// <summary>Cache entry size, in bytes..</summary>
+        private const int EntrySize = 1024;
+
+        [STAThread]
+        public static void Main()
+        {
+            Console.WriteLine();
+            Console.WriteLine(">>> Lifecycle example started.");
+
+            // Configure swap in the current bin directory (where our assembly is located).
+            var binDir = Path.GetDirectoryName(typeof(MultiTieredCacheExample).Assembly.Location);
+            var swapDir = Path.Combine(binDir, "ignite-swap");
+
+            Console.WriteLine(">>> Swap space directory: " + swapDir);
+
+            var cfg = new IgniteConfiguration
+            {
+                DiscoverySpi = new TcpDiscoverySpi
+                {
+                    IpFinder = new TcpDiscoveryMulticastIpFinder
+                    {
+                        Endpoints = new[] { "127.0.0.1:47500" }
+                    }
+                },
+                SwapSpaceSpi = new FileSwapSpaceSpi
+                {
+                    BaseDirectory = swapDir
+                }
+            };
+
+            using (var ignite = Ignition.Start(cfg))
+            {
+                var cacheCfg = new CacheConfiguration
+                {
+                    Name = CacheName,
+                    Backups = 1,
+                    EvictionPolicy = new LruEvictionPolicy
+                    {
+                        MaxSize = 10 // Maximum number of entries that will be stored in
Java heap. 
+                    },
+                    OffHeapMaxMemory = EntrySize * 10, // Limit off-heap to 10 entries.
+                    EnableSwap = true // Data will be swapped to disk if there is no more
space in off-heap space.
+                };
+
+                ICache<int, byte[]> cache = ignite.GetOrCreateCache<int, byte[]>(cacheCfg);
+
+                // Sample data.
+                byte[] dataBytes = new byte[EntrySize];
+
+                // Filling out cache and printing its metrics.
+                PrintCacheMetrics(cache);
+
+                for (int i = 0; i < 100; i++)
+                {
+                    cache.Put(i, dataBytes);
+
+                    if (i%10 == 0)
+                    {
+                        Console.WriteLine(">>> Cache entries created: {0}", i +
1);
+
+                        PrintCacheMetrics(cache);
+                    }
+                }
+
+                Console.WriteLine(">>> Waiting for metrics final update...");
+
+                Thread.Sleep(TcpDiscoverySpi.DefaultHeartbeatFrequency);
+
+                PrintCacheMetrics(cache);
+
+                Console.WriteLine();
+                Console.WriteLine(">>> Example finished, press any key to exit ...");
+                Console.ReadKey();
+            }
+        }
+
+        /// <summary>
+        /// Prints the cache metrics.
+        /// </summary>
+        private static void PrintCacheMetrics(ICache<int, byte[]> cache)
+        {
+            var metrics = cache.GetLocalMetrics();
+
+            Console.WriteLine("\n>>> Cache entries layout: [Total={0}, Java heap={1},
Off-Heap={2}, Swap={3}]",
+                cache.GetSize(CachePeekMode.All), 
+                metrics.Size, metrics.OffHeapEntriesCount, metrics.SwapEntriesCount);
+        }
+    }
+}
\ No newline at end of file


Mime
View raw message