BenchmakComponent.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. NetworkComponent 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(NetworkComponent 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. Session gateSession = networkComponent.Get(s2CLogin.Address);
  37. await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
  38. ++this.k;
  39. if (this.k % 1000 == 0)
  40. {
  41. Log.Info($"{j} Benchmark k: {k}");
  42. }
  43. }
  44. catch (RpcException e)
  45. {
  46. Log.Error(e.ToString());
  47. }
  48. catch (Exception e)
  49. {
  50. Log.Error(e.ToString());
  51. }
  52. }
  53. }
  54. }
  55. public override void Dispose()
  56. {
  57. if (this.Id == 0)
  58. {
  59. return;
  60. }
  61. base.Dispose();
  62. }
  63. }
  64. }