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

Add powershell-http template #1

Merged
merged 5 commits into from Jan 15, 2019

Conversation

Projects
None yet
3 participants
@burtonr
Copy link
Member

burtonr commented Nov 24, 2018

This is an initial powershell-http template
Create an HTTP server in powershell and call the
function/handler.ps1 script with the incoming request
body

Errors are returned with a 500 status code and the
exception message

Signed-off-by: Burton Rheutan rheutan7@gmail.com

Huge thanks to @Jarzamendia for the help in Slack!

Successful invocation:
screenshot from 2018-11-24 09-10-18

Error invocation:
screenshot from 2018-11-24 09-08-48

burtonr added some commits Nov 18, 2018

Add powershell-http template
This is an initial powershell-http template
Create an HTTP server in powershell and call the
function/handler.ps1 script with the incoming request
body

Errors are returned with a 500 status code and the
exception message

Signed-off-by: Burton Rheutan <rheutan7@gmail.com>
Add pull command to readme
Signed-off-by: Burton Rheutan <rheutan7@gmail.com>
@alexellis

This comment has been minimized.

Copy link
Member

alexellis commented Nov 24, 2018

Hi Burton,

Please could you ping John and Andrew to review?

I'd also like to see whether it holds up to some parallel load testing with hey (Golang tool for load testing)

Alex

@alexellis

This comment has been minimized.

Copy link
Member

alexellis commented Nov 24, 2018

@@ -0,0 +1,19 @@
FROM microsoft/powershell:ubuntu16.04

RUN curl -sSLf https://github.com/openfaas-incubator/of-watchdog/releases/download/0.4.2/of-watchdog > /usr/bin/fwatchdog \

This comment has been minimized.

@alexellis

alexellis Nov 24, 2018

Member

Is this the latest release?

This comment has been minimized.

@burtonr

burtonr Nov 26, 2018

Member

from the github releases, 0.4.5 is the latest. I've updated to that

@@ -0,0 +1,19 @@
FROM microsoft/powershell:ubuntu16.04

This comment has been minimized.

@alexellis

alexellis Nov 24, 2018

Member

Is this the latest ubuntu variant?

This comment has been minimized.

@burtonr

burtonr Nov 26, 2018

Member

ubuntu-xenial is the latest (10 days ago). I've updated to that

@@ -0,0 +1,6 @@
# Rename input for better readability
$funcInput = $args

This comment has been minimized.

@alexellis

alexellis Nov 24, 2018

Member

This looks like a good start.

One of the requirements for this template is to provide something that resembles a request/response where the user can set HTTP headers and the status code. Could you look at the Go/Node examples and see if you can find a way to integrate some of that experience and functionality here?

This comment has been minimized.

@burtonr

burtonr Nov 26, 2018

Member

We absolutely can! Powershell is practically an object-oriented language...

I'll work on adding custom objects to pass back to the function handler similar to the Golang template.

@alexellis

This comment has been minimized.

Copy link
Member

alexellis commented Nov 24, 2018

Benchmarking tool - -c for concurrency -n for total requests. See also HTTP method in the options and how to supply data.

https://github.com/rakyll/hey

burtonr added some commits Nov 25, 2018

Update to latest versions
Update base docker image to ubuntu-xenial
Update of-watchdog to 0.4.5

Signed-off-by: Burton Rheutan <rheutan7@gmail.com>
Update to use context and response classes
Adding new class objects to be similar to other http templates

These new classes allow the function to access the request
and other propoerties as well as being able to modify the
response as needed with some sane defaults

Signed-off-by: Burton Rheutan <rheutan7@gmail.com>
@burtonr

This comment has been minimized.

Copy link
Member

burtonr commented Dec 26, 2018

@acornies, @johnmccabe, and @alexellis I've updated the template to use Powershell classes in order to be able to pass the request properties into the function handler.

I've done a quick local test to ensure that the function still functions, the properties are available, and the response is being set correctly. Please let me know what you think and if you come across any issues/errors.

@@ -0,0 +1,10 @@
Param(

This comment has been minimized.

@alexellis

alexellis Jan 5, 2019

Member

Should we perhaps see a function definition here?

This comment has been minimized.

@burtonr

burtonr Jan 7, 2019

Member

I'm not sure what you're looking for here. The FunctionContext includes the input body, headers, querystring, and path for the function to use. Also, the FunctionResponse includes properties for the response body, headers, and a return status code.

This comment has been minimized.

@alexellis

alexellis Jan 7, 2019

Member

Does doesn't look like a function definition? i.e.

function Output-SalesTax {
 param( [int]$Price, [int]$Tax )
 $Price + $Tax
}

or: https://www.faqforge.com/powershell/create-function-powershell/

This comment has been minimized.

@burtonr

burtonr Jan 7, 2019

Member

ah I see. I'm slightly abusing the scripting nature of Powershell here to just have a top-down execution of a file. Now that you bring it up, I agree that having an actual function defined here would be better. I'll make that small update this evening and append this PR.

Thanks for pointing that out!

@acornies
Copy link
Member

acornies left a comment

Is this function supposed to use of-watchdog? I see it now.

@acornies
Copy link
Member

acornies left a comment

I tried out the function on local nomad, swarm providers and it works as expected.

The embedded http server options (Kestrel in this case) could be tuned for some specific scenarios, but I think it's good enough as a basic template using powershell, Kestrel and of-watchdog.

Add curl to Dockerfile
base image does not contain any packages. Need to add curl
to be able to pull in the watchdog binary

Signed-off-by: Burton Rheutan <rheutan7@gmail.com>

@burtonr burtonr force-pushed the burtonr:burtonr-template branch from 70c4d49 to ac55067 Jan 8, 2019

@burtonr

This comment has been minimized.

Copy link
Member

burtonr commented Jan 8, 2019

@alexellis Updated to use a function syntax in the handler.

Also, I ran my loop script on this template and I was surprised at how fast it was responding (even on local Docker Swarm). This is calling the function 10,000 times in a loop in bash:

Hello! Your input was: test 10000

real	0m47.220s
user	0m22.705s
sys	0m15.737s

Also, here's the output from hey:

$ hey -n 10000 -c 5 http://127.0.0.1:8080/function/posher

Summary:
  Total:	3.1451 secs
  Slowest:	0.0095 secs
  Fastest:	0.0007 secs
  Average:	0.0016 secs
  Requests/sec:	3179.5656
  
  Total data:	230000 bytes
  Size/request:	23 bytes

Response time histogram:
  0.001 [1]	|
  0.002 [6861]	|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.002 [2915]	|■■■■■■■■■■■■■■■■■
  0.003 [160]	|■
  0.004 [20]	|
  0.005 [13]	|
  0.006 [17]	|
  0.007 [7]	|
  0.008 [2]	|
  0.009 [2]	|
  0.009 [2]	|


Latency distribution:
  10% in 0.0013 secs
  25% in 0.0014 secs
  50% in 0.0015 secs
  75% in 0.0016 secs
  90% in 0.0019 secs
  95% in 0.0022 secs
  99% in 0.0030 secs

Details (average, fastest, slowest):
  DNS+dialup:	0.0000 secs, 0.0007 secs, 0.0095 secs
  DNS-lookup:	0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:	0.0000 secs, 0.0000 secs, 0.0007 secs
  resp wait:	0.0015 secs, 0.0007 secs, 0.0078 secs
  resp read:	0.0000 secs, 0.0000 secs, 0.0041 secs

Status code distribution:
  [200]	10000 responses
@alexellis
Copy link
Member

alexellis left a comment

LGTM

@alexellis alexellis merged commit 07e9e35 into openfaas-incubator:master Jan 15, 2019

@alexellis

This comment has been minimized.

Copy link
Member

alexellis commented Jan 15, 2019

Hi Burton the results look good and thanks for getting the handler in place for some more consistency with the other templates.

We may need to do some longer burn-in tests but initial version seems to be working well.

Alex

@alexellis

This comment has been minimized.

Copy link
Member

alexellis commented Jan 15, 2019

Thanks and well done!

@burtonr burtonr deleted the burtonr:burtonr-template branch Jan 15, 2019

@alexellis

This comment has been minimized.

Copy link
Member

alexellis commented Jan 16, 2019

Now how do we manage dependencies with this like a powershell module?

@burtonr

This comment has been minimized.

Copy link
Member

burtonr commented Jan 16, 2019

That would be something to look in to for sure! I'll open an issue so it doesn't get lost here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment