New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create dotnet core FastHttpApi http server #4178

Merged
merged 36 commits into from Nov 13, 2018

Conversation

Projects
None yet
4 participants
@IKende
Copy link
Contributor

IKende commented Nov 6, 2018

dotnet core FastHttpApi

IKende added some commits Nov 6, 2018

@IKende

This comment has been minimized.

Copy link
Contributor Author

IKende commented Nov 7, 2018

NO RESULTS (Did framework launch?) What do I need to do?
log display server started!

beetlex-fasthttpapi: [Info:11/07/2018 12:10:34] server start@:::8080
beetlex-fasthttpapi: [Info:11/07/2018 12:10:34] FastHttpApi Server started!
beetlex-fasthttpapi: ServerGC:True
beetlex-fasthttpapi: BeetleX Http Server Listen :::8080

i tested successfully with wrk4.1.0 on the local server

RUN dotnet publish -c Release -o out

WORKDIR /app
COPY --from=build /app/out ./

This comment has been minimized.

@nbrady-techempower

nbrady-techempower Nov 7, 2018

Member

This doesn't work for me locally because you're not using multi-stage builds. Can you remove the COPY line and change to WORKDIR /app/out

@nbrady-techempower

This comment has been minimized.

Copy link
Member

nbrady-techempower commented Nov 7, 2018

After making the change to the dockerfile I suggested above, I can get the server running but it's refusing connections

@IKende

This comment has been minimized.

Copy link
Contributor Author

IKende commented Nov 7, 2018

After making the change to the dockerfile I suggested above, I can get the server running but it's refusing connections
This code can run on Linux Ubuntu\ Windows and pass the wrk4.1.0 test.
This code is not using ASP.net core, is the use of HTTP TCP base, do I need additional configuration?
but I use ASP.net core project to test success .

@misiek08

This comment has been minimized.

Copy link

misiek08 commented Nov 7, 2018

I'm not sure - trying to check it myself, but it will take me some time.

Check if it's not a problem with IPv6. I tried your image alone and it works, but requests are served in IPv6 and maybe that's the problem. Force the server to listen on 0.0.0.0.

EDIT: Nope, it's not IPv6 issue if I setup it correctly.

@misiek08

This comment has been minimized.

Copy link

misiek08 commented Nov 7, 2018

Container with your server is dying right after starting. Console.Read (and Console.ReadLine) won't work as daemon mode. When container is run as background job it don't get any input or even tty, so it can't wait for reading anything and exits immediately.

Similar issues:
https://stackoverflow.com/questions/38549006/docker-container-exits-immediately-even-with-console-readline-in-a-net-core-c
https://stackoverflow.com/questions/40506122/control-lifetime-of-net-core-console-application-hosted-in-docker

IKende added some commits Nov 7, 2018

dockerfile add
FROM microsoft/dotnet:2.1-runtime-nanoserver
@IKende

This comment has been minimized.

Copy link
Contributor Author

IKende commented Nov 8, 2018

Container with your server is dying right after starting. Console.Read (and Console.ReadLine) won't work as daemon mode. When container is run as background job it don't get any input or even tty, so it can't wait for reading anything and exits immediately.

Similar issues:
https://stackoverflow.com/questions/38549006/docker-container-exits-immediately-even-with-console-readline-in-a-net-core-c
https://stackoverflow.com/questions/40506122/control-lifetime-of-net-core-console-application-hosted-in-docker

Thank you very much!

IKende added some commits Nov 8, 2018

@nbrady-techempower

This comment has been minimized.

Copy link
Member

nbrady-techempower commented Nov 8, 2018

@IKende can you change your directory name to beetlex-fasthttpapi (all lowercase) or beetlex or fasthttpapi not sure which is your framework name

@IKende

This comment has been minimized.

Copy link
Contributor Author

IKende commented Nov 9, 2018

@IKende can you change your directory name to beetlex-fasthttpapi (all lowercase) or beetlex or fasthttpapi not sure which is your framework name

Okay I'll change it.

}


public class BeetleXHttpServer : BackgroundService

This comment has been minimized.

@davidfowl

davidfowl Nov 9, 2018

Contributor

You can just use IHostedService instead of BackgroundService. That way you don't have to spin on the token.

This comment has been minimized.

@IKende

IKende Nov 9, 2018

Author Contributor

Thank you. I'm going to modify it.

});

var result = builder.RunConsoleAsync();
result.Wait();

This comment has been minimized.

@davidfowl

davidfowl Nov 9, 2018

Contributor

Don’t do run console async just use Run


public async Task StopAsync(CancellationToken cancellationToken)
{
return;

This comment has been minimized.

@davidfowl

davidfowl Nov 9, 2018

Contributor

You probably want to stop the server here

This comment has been minimized.

@IKende

IKende Nov 9, 2018

Author Contributor

Can I do this?

            var builder = new HostBuilder()
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddHostedService<BeetleXHttpServer>();
                });
            var result = builder.Start();
        public virtual async Task StopAsync(CancellationToken cancellationToken)
        {
            mApiServer.BaseServer.Dispose();
            return;
        }

This comment has been minimized.

@davidfowl

davidfowl Nov 9, 2018

Contributor

Sure

This comment has been minimized.

@IKende

IKende Nov 9, 2018

Author Contributor

thank

@IKende

This comment has been minimized.

Copy link
Contributor Author

IKende commented Nov 10, 2018

@nbrady-techempower
What do I need to do merge this pr?

sb.AppendLine("Date: " + DateTime.Now.ToUniversalTime().ToString("r"));
sb.AppendLine("");
sb.Append(helloword);
PlaintextBytes = Encoding.UTF8.GetBytes(sb.ToString());

This comment has been minimized.

@davidfowl

davidfowl Nov 10, 2018

Contributor

I don’t think this is legal. You need to create the response every single request, you can’t cache it.

This comment has been minimized.

@nbrady-techempower

nbrady-techempower Nov 10, 2018

Member

@IKende please look at the test requirements. For the json test, you must instantiate and serialize an object on every request. It's also not acceptable to cache the headers: https://frameworkbenchmarks.readthedocs.io/en/latest/Project-Information/Framework-Tests/#test-types

This comment has been minimized.

@IKende

IKende Nov 11, 2018

Author Contributor

I think can use this approach and see that other platform languages are also using this approach
https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Java/netty/src/main/java/hello/HelloServerHandler.java
i removed this test.

public virtual void SessionReceive(IServer server, SessionReceiveEventArgs e)
{
PipeStream stream = e.Stream.ToPipeStream();
string line = null;

This comment has been minimized.

@davidfowl

davidfowl Nov 10, 2018

Contributor

I haven’t looked but does this assume you’ll get the entire buffer in a single call?

This comment has been minimized.

@IKende

IKende Nov 11, 2018

Author Contributor

Yes, I think about it. There is a bug here, in the multi-receive with request, I need to fix it!

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

This comment has been minimized.

@davidfowl

davidfowl Nov 10, 2018

Contributor

Delete this file

This comment has been minimized.

@IKende

IKende Nov 11, 2018

Author Contributor

okay

IKende added some commits Nov 11, 2018

private static string mDate;
public static void Main(string[] args)
{
mDate = DateTime.Now.ToUniversalTime().ToString("r");

This comment has been minimized.

@davidfowl

davidfowl Nov 11, 2018

Contributor

You can’t cache the date header either. It needs to update (we update it every second)

private static string mDate;
public static void Main(string[] args)
{

This comment has been minimized.

@davidfowl

davidfowl Nov 12, 2018

Contributor

nit: Remove extra space.

This comment has been minimized.

@IKende

IKende Nov 12, 2018

Author Contributor

thank

@davidfowl
Copy link
Contributor

davidfowl left a comment

I think this is fine now 😬.

@nbrady-techempower

This comment has been minimized.

Copy link
Member

nbrady-techempower commented Nov 12, 2018

This looks good now. One last thing for me, could you rename the FastHttpApi/ directory to beetlex and we can get this merged. Thanks!

@IKende

This comment has been minimized.

Copy link
Contributor Author

IKende commented Nov 13, 2018

@nbrady-techempower
Thanks, the directory has been changed to beetlex

@nbrady-techempower nbrady-techempower merged commit 7442995 into TechEmpower:master Nov 13, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment