Guest User

Untitled

a guest
Sep 18th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. Rows are missing from CassandraDB?
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using FluentCassandra;
  8.  
  9. namespace ConsoleApplication2
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. var session = new CassandraSession("Tester", "localhost");
  16.  
  17. CreateData(session);
  18. SelectData(session);
  19. Console.WriteLine("Done");
  20. Console.ReadLine();
  21. }
  22.  
  23. private static void SelectData(CassandraSession session)
  24. {
  25. using (var db = new CassandraContext(session))
  26. {
  27. var users = db.GetColumnFamily("Users2");
  28. var count = users.AsObjectQueryable<User>().Count();
  29. Console.WriteLine("Counted: " + count.ToString());
  30. }
  31. }
  32.  
  33. private static void CreateData(CassandraSession session)
  34. {
  35. var startTime = DateTime.UtcNow;
  36. for (int index = 0; index < 11 * 1000; index++)
  37. {
  38. using (var db = new CassandraContext(session))
  39. {
  40. var users = db.GetColumnFamily("Users2");
  41. dynamic user = users.CreateRecord(index);
  42. user.Name = "UserX" + index.ToString();
  43. user.Password = "PasswordX" + index.ToString();
  44. db.Attach(user);
  45. db.SaveChanges();
  46. if (index % 1000 == 0)
  47. {
  48. var taken = DateTime.UtcNow - startTime;
  49. Console.WriteLine(string.Format("{0} thousand in {1} seconds", (index / 1000) + 1, taken.TotalSeconds));
  50. }
  51. }
  52. }
  53. }
  54. }
  55.  
  56. class User
  57. {
  58. public string Name { get; set; }
  59. public string Text { get; set; }
  60. }
  61. }
  62.  
  63. Output:
  64. 1 thousand in 0.2760158 seconds
  65. 2 thousand in 0.8180468 seconds
  66. 3 thousand in 1.3700784 seconds
  67. 4 thousand in 1.8971085 seconds
  68. 5 thousand in 2.4091378 seconds
  69. 6 thousand in 3.0791761 seconds
  70. 7 thousand in 3.6002059 seconds
  71. 8 thousand in 4.126236 seconds
  72. 9 thousand in 4.8292762 seconds
  73. 10 thousand in 5.3513061 seconds
  74. 11 thousand in 5.8543349 seconds
  75. Counted: 9018
  76. Done
Add Comment
Please, Sign In to add comment