BenchmakComponent.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using Base;
  3. namespace Model
  4. {
  5. [ObjectEvent]
  6. public class BenchmakComponentEvent : ObjectEvent<BenchmakComponent>, IAwake<string>
  7. {
  8. public void Awake(string address)
  9. {
  10. BenchmakComponent component = this.GetValue();
  11. component.Awake(address);
  12. }
  13. }
  14. public class BenchmakComponent : Component
  15. {
  16. private int k;
  17. public void Awake(string address)
  18. {
  19. NetOuterComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();
  20. for (int i = 0; i < 400; i++)
  21. {
  22. TestAsync(networkComponent, address, i);
  23. }
  24. }
  25. private async void TestAsync(NetOuterComponent networkComponent, string address, int j)
  26. {
  27. using (Session session = networkComponent.Create(address))
  28. {
  29. int i = 0;
  30. while (i < 10000)
  31. {
  32. ++i;
  33. try
  34. {
  35. R2C_Login s2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login { Account = "abcdef", Password = "111111" });
  36. using (Session gateSession = networkComponent.Create(s2CLogin.Address))
  37. {
  38. await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
  39. }
  40. ++this.k;
  41. if (this.k % 1000 == 0)
  42. {
  43. Log.Info($"{j} Benchmark k: {k}");
  44. }
  45. }
  46. catch (RpcException e)
  47. {
  48. Log.Error(e.ToString());
  49. }
  50. catch (Exception e)
  51. {
  52. Log.Error(e.ToString());
  53. }
  54. }
  55. }
  56. }
  57. public override void Dispose()
  58. {
  59. if (this.Id == 0)
  60. {
  61. return;
  62. }
  63. base.Dispose();
  64. }
  65. }
  66. }