Programming Notes ✍️ – Telegram
Programming Notes ✍️
12 subscribers
65 photos
1 file
22 links
Download Telegram
کامپایلر گو یک Ahead Of Time compilation است. تفاوت AOT با JIT در این است که کامپایلر های AOT مستقیم کد ما را تبدیل به machine code می کنند اما در کامپایتر های JIT کد ما تبدیل به یک کد میانی Bytecode می شود و در زمان اجرا توسط runtime engine هر قسمت از برنامه که مورد استفاده قرار می گیرد، تفسیر می شود و تبدیل به machine code می شود.
The service discovery mechanism in Kubernetes works as follows:

Service registration:
When a service is created in Kubernetes, it is assigned a unique DNS name and IP address.

DNS resolution:
Other services within the Kubernetes cluster can resolve the DNS name of a service to obtain its corresponding IP address.

Load balancing:
When a service receives requests from other services, Kubernetes automatically load balances the traffic across the available pods that belong to that service. This ensures scalability and fault tolerance.

Service updates:
If the number of pods associated with a service changes (e.g., due to scaling or failures), Kubernetes dynamically updates the service’s DNS record to reflect the current set of available endpoints.
disaggregation cloudification orchestration openapi
vertical disaggregation, where network functions decouple software from hardware,
allowing multiple combinations to be used

• horizontal disaggregation, where established network functions are decomposed into
more granular elements and new interfaces are designed and specified
پوینتی که همیشه باید مد نظر بگیرید :‌
هیچوقت کانسپت های مهندسی نرم افزار و برنامه نویسی رو به زبان فارسی نخونید.
👍2
mux http server with rate limiter
package main

import (
"encoding/json"
"errors"
"fmt"
"github.com/gorilla/mux"
"go.uber.org/ratelimit"
"log"
"net"
"net/http"
"sync"
"time"
)

const PORT = 8080
const RATELIMIT = 2

// RateLimit middleware.
func RateLimit(rate int) func(next http.Handler) http.Handler {
var lmap sync.Map

return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
http.Error(w, fmt.Sprintf("invalid RemoteAddr: %s", err), http.StatusInternalServerError)

return
}

lif, ok := lmap.Load(host)
if !ok {
lif = ratelimit.New(rate)
}

lm, ok := lif.(ratelimit.Limiter)
if !ok {
http.Error(w, "internal middleware error: typecast failed", http.StatusInternalServerError)

return
}

log.Println("req:", r.RemoteAddr, "Rate:", rate, "Time:", time.Now())

lm.Take()
lmap.Store(host, lm)

next.ServeHTTP(w, r)
})
}
}

func getHello(w http.ResponseWriter, r *http.Request) {
var user = map[string]interface{}{
"name": "John Doe",
"age": 42,
"message": "Hello world!",
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
json.NewEncoder(w).Encode(user)
}

func main() {
r := mux.NewRouter()
r.Use(RateLimit(RATELIMIT))
r.HandleFunc("/api", getHello)
fmt.Printf("listening on port %d\n", PORT)
err := http.ListenAndServe(fmt.Sprintf(":%d", PORT), r)

if errors.Is(err, http.ErrServerClosed) {
log.Fatal("server closed\n")
}

if err != nil {
log.Fatal("error occurred :", err)
}
}
👍2
Note: Only the sender should close a channel, never the receiver. Sending on a closed channel will cause a panic.

Another note: Channels aren't like files; you don't usually need to close them. Closing is only necessary when the receiver must be told there are no more values coming, such as to terminate a range loop.
Atomicity: All operations in a transaction either succeed or all are rolled back.

Consistent: The database integrity constraints are valid on completion of the transaction.

Isolated: Simultaneously occurring transactions do not interfere with each other. Contentious concurrent access is moderated by the
database so that transactions appear to run sequentially.

Durable: Irrespective of hardware or software failures, the updates made by the transaction are permanent.
👍2