MCPcopy Create free account
hub / github.com/eth-easl/dirigent / Fire

Function Fire

async/fire.go:76–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74var counter int32 = 0
75
76func Fire() {
77
78 logrus.Info("Invocating async function")
79
80 ////////////////////////////////////
81 // INVOKE FUNCTION
82 ////////////////////////////////////
83
84 client := http.Client{
85 Timeout: 5 * time.Second,
86 Transport: &http2.Transport{
87 AllowHTTP: true,
88 DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) {
89 return net.Dial(network, addr)
90 },
91 DisableCompression: true,
92 },
93 }
94
95 req, err := http.NewRequest("GET", "http://localhost:8080", nil)
96 if err != nil {
97 panic(err.Error())
98 }
99
100 req.Host = "test"
101
102 req.Header.Set("workload", "empty")
103 req.Header.Set("requested_cpu", strconv.Itoa(1))
104 req.Header.Set("requested_memory", strconv.Itoa(1))
105 req.Header.Set("multiplier", strconv.Itoa(0))
106
107 resp, err := client.Do(req)
108 if err != nil {
109 logrus.Fatalf("Failed to establish a HTTP connection - %s\n", err)
110 }
111
112 body, err := io.ReadAll(resp.Body)
113 if err != nil || resp == nil || resp.StatusCode != http.StatusOK {
114 msg := ""
115 if err != nil {
116 msg = err.Error()
117 } else if resp == nil {
118 msg = fmt.Sprintf("empty response - status code: %d", resp.StatusCode)
119 } else if resp.StatusCode != http.StatusOK {
120 msg = fmt.Sprintf("%s - status code: %d", body, resp.StatusCode)
121 }
122 logrus.Debugf("HTTP timeout for function")
123 logrus.Fatalf(msg)
124 }
125
126 fmt.Println(string(body[:]))
127
128 code := string(body[:])
129
130 time.Sleep(750 * time.Millisecond)
131
132 req, err = http.NewRequest("GET", "http://localhost:8082", strings.NewReader(code))
133 if err != nil {

Callers 2

latencyFunction · 0.85
tpFunction · 0.85

Calls 1

SetMethod · 0.65

Tested by

no test coverage detected