你的位置:首页 > ASP.net教程

[ASP.net教程]LevelDB.NET性能测试


    最近了解了一下LevelDB,发觉这个嵌入式的K-V数据性能不错,所以顺便想在使用层面了解一下.由于LevelDB也有针对.net的实现,所以就针对了LevelDB.NET进行了一个简单的读写压力测试.为了更客观的体现测试结构所以添加了大量的数据,和GET操作的时候随机已经有的KEY进行.

Set操作

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public static void WriteTest(object state)
        {
            while (true)
            {
 
                User user = new User();
                string id = GetKey().ToString("000000000000000000000");
                user.Name = id;
                user.EMail = id + "@msn.com";
                user.CrateTime = DateTime.Now;
                user.City = "GZ" + id;
                user.Country = "CN" + id;
                user.Address = "sdfffffffffffffffffffffffffafjsdfjsljfsjfls"+id;
                user.Phone = id;
                user.Region = "gd";
                db.Set(user.Name, user);
                System.Threading.Interlocked.Increment(ref mCount);
 
            }
        }



Get操作

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
while (true)
            {
                User user;
 
                int index = ran.Next(100000, 500000);
                if (index == li)
                {
                    Console.WriteLine(index);
                }
                li = index;
 
                user = db.Get<User>(index.ToString("000000000000000000000"));
                System.Threading.Interlocked.Increment(ref mIndex);
                System.Threading.Interlocked.Increment(ref mCount);
 
            }



总结

        LevenDB.Net的写入速度非常高效,在单线程写入的情况都可以达到接近5W/秒的效率,而在获取上的效率更高5线程的并发读竟然可以达到15W/秒的能力....这读效果是相当的可观.