Code Monkey home page Code Monkey logo

Comments (4)

droyad avatar droyad commented on September 28, 2024

@wahmedswl, I ran the load test exe with the following settings:

const int Servers = 1;
const int ClientsPerServer = 1;
const int RequestsPerClient = 2000;

This took around 3,000ms, or 1.5ms per request, which is quite fast. If you do think there is a performance problem, please share the code and setup information that will allow me to reproduce it.

from halibut.

wahmedswl avatar wahmedswl commented on September 28, 2024

@droyad setup is nothing fancy. I am running Halibut.SampleServer and Halibut.SampleClient.

Client

class Program
    {
        public static void Main(string[] args)
        {

            Console.Title = "Halibut Client";
            var certificate = new X509Certificate2("HalibutClient.pfx");

            var hostName = args.FirstOrDefault() ?? "localhost";
            var port = args.Skip(1).FirstOrDefault() ?? "8433";
            using (var runtime = new HalibutRuntime(certificate))
            {
                //Begin make request of Listening server
                //var calculator = runtime.CreateClient<ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");
                //End make request of Listening server

                //Begin make request of Polling server
                //var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);
                //runtime.Listen(endPoint);
                //runtime.Trust("EF3A7A69AFE0D13130370B44A228F5CD15C069BC");
                //var calculator = runtime.CreateClient<ICalculatorService>("poll://SQ-TENTAPOLL", "2074529C99D93D5955FEECA859AEAC6092741205");
                //End make request of Polling server

                //Begin make request of WebSocket Polling server
                AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:8433");
                runtime.ListenWebSocket("https://+:8433/Halibut");
                runtime.Trust("EF3A7A69AFE0D13130370B44A228F5CD15C069BC");
                var calculator = runtime.CreateClient<ICalculatorService>("poll://SQ-TENTAPOLL", "2074529C99D93D5955FEECA859AEAC6092741205");
                //End make request of WebSocket Polling server

                while (true)
                {
                    Benchmark(() =>
                    {
                        var result = calculator.Add(12, 18);
                        result = calculator.Subtract(10, 5);
                    }, name: "Benchmark", noOfIterations: 1000);

                    Console.ReadKey();
                }
            }
        }

        static void AddSslCertToLocalStoreAndRegisterFor(string address)
        {
            var certificate = new X509Certificate2("HalibutSslCertificate.pfx", "password");
            var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadWrite);
            store.Add(certificate);
            store.Close();


            var proc = new Process()
            {
                StartInfo = new ProcessStartInfo("netsh", $"http add sslcert ipport={address} certhash={certificate.Thumbprint} appid={{2e282bfb-fce9-40fc-a594-2136043e1c8f}}")
                {
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    UseShellExecute = false
                }
            };
            proc.Start();
            proc.WaitForExit();
            var output = proc.StandardOutput.ReadToEnd();

            if (proc.ExitCode != 0 && !output.Contains("Cannot create a file when that file already exists"))
            {
                Console.WriteLine(output);
                Console.WriteLine(proc.StandardError.ReadToEnd());
                throw new Exception("Could not bind cert to port");
            }
        }

        public static double Benchmark(Action action, string name = "", int noOfIterations = 1)
        {
            if (action == null) { return 0; }

            var stopWatch = Stopwatch.StartNew();
            for (int i = 0; i < noOfIterations; i++) { action(); }
            stopWatch.Stop();
            var timeTaken = stopWatch.Elapsed.TotalMilliseconds;

            if (!string.IsNullOrEmpty(name))
            {
                var sb = new StringBuilder();
                sb.Append(name);
                sb.Append(" - TimeTaken: ");
                sb.Append(timeTaken);
                sb.Append("ms, ");
                sb.Append(timeTaken / 1000);
                sb.Append("s");
                Console.WriteLine(sb.ToString());
            }

            return timeTaken;
        }
    }

Server

class Program
    {
        const string SslCertificateThumbprint = "6E5C6492129B75A4C83E1A23797AF6344092E5C2"; // For WebSockets. This is different to the internally configured thumbprint
        public static void Main(string[] args)
        {
            
            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();
            services.Register<ICalculatorService>(() => new CalculatorService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                //Although this is the "Server" because it is the thing handling a request
                //in Octopus terms, this would be the Tentacle, being asked to do some work

                //Begin Listening Setup
                //server.Listen(endPoint);
                //server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
                //End Listening Setup

                //Begin Polling Setup
                //server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:8433"), "2074529C99D93D5955FEECA859AEAC6092741205"));
                //End Polling Setup

                //Begin WebSocket Polling Setup

                server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("wss://localhost:8433/Halibut"), SslCertificateThumbprint));
                //End WebSocket Polling Setup

                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");
                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                        return;

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                        return;

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
    }

from halibut.

wahmedswl avatar wahmedswl commented on September 28, 2024

@droyad i have also run the same sample, Halibut.SampleLoadTest and output is

Done in: 20,841ms (Debug)
Done in: 57,443ms (Release)

Its strange that, debug build is faster than release.

from halibut.

droyad avatar droyad commented on September 28, 2024

@wahmedswl

Thanks for that. I get similar results, however if I turn down the log output to Warning (.MinimumLevel.Warning()), I get in the 3-5 second range. I also expect WebSockets to be a bit slower than Listening/Polling due to the HTTP and WebSockets protocol overhead.

from halibut.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.