28 Temmuz 2021 Çarşamba

Systems Modeling Language - SysML

Giriş
2000 yılında geliştirilmeye başlandı. UML üzerine inşa edildi. Açıklaması şöyle
In the early 2000s, members of the International Council on Systems Engineering (INCOSE) and the Object Management Group (OMG) joined together to create a graphical modeling language that was tailored to the needs of systems engineers. This produced the Systems Modeling Language, or SysML, built on top of the software-focused Unified Modeling Language (UML).
SysML v1
Açıklaması şöyle
SysML v1 received mixed reviews from the systems engineering community after it was released in 2007. Its UML foundation saved designers of the language from reinventing core concepts in modeling and representation. And a community of UML tool vendors was ready to support it. However, SysML inherited UML’s weaknesses along with its strengths. There was a lack of connection between system structure and behavior. The representational approach was esoteric and rigid, making training difficult. Lack of interoperability between tools made sharing models painful. And ambiguous rules for completeness of diagrams relative to the model made many errors easy to create and hard to detect.

Because of these problems, the systems engineering community has been relatively slow to adopt the model-based systems engineering (MBSE) approach. And entire competing MBSE languages, paradigms, and tool suites have been developed by individual organizations. If systems engineering is the universal solvent into which all domain experts can pour their knowledge, SysML v1 has left something to be desired.

27 Temmuz 2021 Salı

ACID - Serializable Nedir ?

Giriş
Şeklen şöyle

SQL Server için şeklen şöyle
 Açıklaması şöyle. Range içine yeni satır eklenemediği veya silinemediği için Phantom Read engellenir.
When T1 queries a range or records, it acquires a different type of lock, signifying that it belongs to the range.
This lock is called Range-lock, (Range S-S is its status) instead of S for Read lock and X for the Write lock.
So when T1 queries a range, all the rows are range-locked.
If T2 tries to insert a new row, which might affect this range, then T2 will be blocked until T1 completes and releases the Range lock.
However, T2 can read the rows, as Range-lock allowed shared reads, but prevents certain Writes.
Örnek - Spring
Şöyle yaparız
@Transactional(isolation = Isolation.SERIALIZABLE)

ACID - Non Repeatable Read

Giriş
Şeklen şöyle

SQL Server için şeklen şöyle
Açıklaması şöyle
This can happen when a Transaction tries to read the DB row multiple times and gets different results each time e.g. if T1 reads a DB row at 2 different times, and in between these 2 reads, T2 updates the row.
Açıklaması şöyle
If a transaction reads a database row without applying a shared lock on the newly fetched record, then a concurrent transaction might change this row before the first transaction has ended.
Örnek
Aynı veriyi iki defa okuyup farklı sonuçlar alan bir örnek şöyle
The best example is, a client might order a product based on a stock quantity value that is no longer a positive integer). With the Read-Committed isolation level, it is possible to avoid non-repeatable (fuzzy) reads.
Örnek
Şeklen şöyle

Açıklaması şöyle
1. Alice and Bob start two database transactions.
2. Bob’s reads the post record and title column value is Transactions.
3. Alice modifies the title of a given post record to the value of ACID.
4. Alice commits her database transaction.
5. If Bob’s re-reads the post record, he will observe a different version of this table row.



ACID - Dirty Read ve Dirty Write - Commitlenmemiş Veriye Erişmek

Giriş
Şeklen şöyle

SQL Server için şeklen şöyle
Dirty Read
Kısaca commit'lenmemiş bir transaction'a ait veriyi okumak anlamına gelir. Bizim transaction'ımız diğer transaction'a ait veriyi okur, ancak daha sonra diğer transaction rollback yapmaya karar verir. Bu durumda Dirty Read olur. Açıklaması şöyle
A dirty read happens when a transaction is allowed to read the uncommitted changes of some other concurrent transaction. Taking a business decision on a value that has not been committed is risky because uncommitted changes might get rolled back.
Dirty Write
Bir  transaction, bir başka transaction'a ait veriyi de yazar, ancak daha sonra diğer transaction rollback yapmaya karar verir. Bu durumda Dirty Write olur 

26 Temmuz 2021 Pazartesi

Content Delivery Network - CDN

Giriş
Açıklaması şöyle. CDN sık kullanılan şeyleri cache'ler
A CDN is a network of servers that are distributed around the world, and are used to deliver content to users based on their location.

When a user requests content from a CDN, the closest server to the user will deliver the content, rather than having the user’s request be routed to the origin server. The content is then cached on the CDN server, so that if another user in the same location requests the same content, it can be quickly delivered from the cache.
Açıklaması şöyle. Cache'lenen şey herhangi bir şey olabilir. 
They allow websites to cache frequently accessed assets — such as pictures, videos, or JavaScript files — to make the website more performant and avoid downtime.
Açıklaması şöyle
Also, there are generally two kinds of CDNs conceptually
1. Push CDN: You are responsible to upload data to the CDN servers
2. Pull CDN: The CDN will pull data from your servers (origin servers)





Google Cloud

Giriş
AWS ve Google Cloud karşılaştırması şeklen şöyle

Bir başka yazı burada

Google Cloud Dataflow
Serverless stream ve batch processing içindir.

Google Cloud Shell
Linux bilgisayar gibi. python3, git, docker gibi komutlar mevcut. 

gcloud komutu
gcloud komutu yazısına taşıdım

MemoryStore
Açıklaması şöyle
Redis is a popular open source in memory database. It is available as a managed service on AWS (Elasticache) and Google Cloud (Memorystore).
Push Notification
Açıklaması şöyle
Notifications of Whatsapp and Reddit are triggered by push notifications sent from Google servers, received by Google Play Services, a system app which always runs in background.

Depending on the received push notification type such a push notification can be displayed directly without even starting the app it is targeting or the push message is delivered to the app (which is automatically started if it is not already running) and the app can then "translate" the push message into a notification (in case of Whatsapp this require e.g. decryption of the received message or even fetching additional data from Whatsapp servers).
Bigtable
Google Cloud Veri Tabanları yazısına taşıdım

BigQuery
Google Cloud Veri Tabanları yazısına taşıdım


Pub/Sub
Google Cloud Pub/Sub yazısına taşıdım

Google Cloud Storage
Google Cloud Storage yazısına taşıdım

Google Cloud Functions
Serverless ve event driven geliştirme imkanı sağlar. AWS karşılığı Lambda, Azure karşılığı ise Azure Functions

Google Cloud WorkFlows
Açıklaması şöyle
A cloud-based workflow engine managed by Google Cloud. Workflows can be defined in either YAML or JSON format. Furthermore, the orchestrator uses HTTP to interact with the tasks.
Google Kubernetes Engine (GKE)




Http Long Polling

Giriş
Açıklaması şöyle
In long polling, clients can request information from the server to expect that the server may not respond immediately. If the server has no new data for the client when the poll is received, instead of sending an empty response, the server holds the request open and waits for response information to become available. Once it does have new information, the server immediately sends the response to the client, completing the open request. Upon receipt of the server response, the client can immediately issue another server request for future updates. This gives a lot of improvements in latencies, throughputs, and performance. However, the long polling request can timeout or receive a disconnect from the server. In that case, the client has to open a new request.

23 Temmuz 2021 Cuma

Trigonometrik Fonksiyonlar - PI Sayısı

Hazır Sabitler
Örnek - C ve C++
Şöyle yaparız
#include <math.h>
M_PI şeklinde kullanılır
Örnek - C++ - 20
Şöyle yaparız
std::numbers::pi
Kendimiz Hesaplarsak
Örnek - C++
Şöyle yaparız
static const double PI = std::atan(1) * 4;
Örnek - C#
Şöyle hesaplanabilir.

Kod olarak şöyle yaparız. Bölümdeki böleni hep 2 artırırız. Bölme işlemi bir artı bir de eksi olacak işareti ile toplama eklenir.
double number = 0;
double pi;
int i = 1;

do 
{
  if ((i/2) % 2 == 0)
  {
    number += (double)(1) / i;
  }
  else
  {
    number -= (double)(1) / i;
  }
  pi = 4 * number;
  i += 2;
} while (Math.Round(pi,5) != 3.14159);

Trigonometrik Fonksiyonlar - Sinüs

Giriş
Sinüs temel trigonometrik fonksiyonlardan birisi. sin (sinüs) fonksiyonu ile dikkat edilmesi gereken nokta, sin (PI) çağrısı sonucunda,  PI sayısı floating sayı olarak tam temsil edilemediğinden 0'ı vermeyebilir.

Çıktı Birimi
Sinüs radyan cinsinden çalışır. Dolayısıyla şöyle yapmak gerekir.
public static double sin(double angle){    
  angle = Math.toRadians(angle);
  return Math.sin(angle);
}
Sinüs  Hesaplama

Örnek

sinüsü hesaplamak için Taylor Serisi kullanılabilir.

Örnek
Tablo kullanarak hesaplanabilir.


22 Temmuz 2021 Perşembe

HTTP/3 - HTTP over QUIC

Tarayıcı Desteği
Tarayıcımızın HTTP/3 destekleyip desteklemediğini görmek için  quic.nginx.org adresine gidilebilir.

TCP Kullanmıyor, QUIC Kullanıyor
Açıklaması şöyle.
Instead of TCP, HTTP/3 uses a new protocol, developed in 2012 by Google, called QUIC (pronounced “quick”).
QUIC'in Özellikleri
Bazı özellikleri şöyle
- Instead of TCP, HTTP/3 uses a new protocol, QUIC, developed by Google in 2012. QUIC runs over UDP, the User Datagram Protocol.
- QUIC provides native multiplexing, and lost packets only impact the streams where data has been lost. This resolves the head-of-line blocking issue in HTTP/2.
- QUIC provides flow control for stream data and all HTTP/3 frame types that are sent on streams. Therefore, all frame headers and payloads are subject to flow control.
- The request and response headers are compressed by QPACK instead of HPACK in HTTP/2.
- Several HTTP/3 frames are used to manage server push.
Native Multiplexing
Bu sayede sayfayı paralel yüklemek mümkün. Açıklaması şöyle.
Before HTTP/2, browsers could only send one request to the server at a time. This made website loading significantly slower because the browser only loaded one asset, like CSS or JavaScript, at a time. HTTP/2 introduced the ability to load more than one asset at a time, but TCP was not made for this. If one of the requests failed, TCP would make the browser redo all the requests. Because TCP was removed in HTTP/3 and replaced by QUIC, HTTP/3 solved this problem. With HTTP/3, the browser only needs to redo the failed request. Because of this, HTTP/3 is faster and more reliable.
TLS
Açıklaması şöyle. QUIC protokolü de TLS kullanıyor
HTTP/3 optimizes the “handshake” that allows browsers HTTP requests to be encrypted. QUIC combines the initial connection with a TLS handshake, making it secure by default and faster.


21 Temmuz 2021 Çarşamba

Amazon Web Service (AWS) Veri Tabanları

Giriş
Veri tabanları şöyle
1. Relational Database Service (RDS)
    Postgres, MySQL, etc. with Full SQL Support. AWS RDS yazısına taşıdım
2. RedShift
    Data warehouse with Full SQL Support
3. ElastiCache
4. DynamoDB
    NoSQL database : DynamoDB yazısına taşıdım
5. Aurora
    Serverless databases with Full SQL Support. AWS Aurora yazısına taşıdım

6. Database migration service (DMS)
7. Elastic Map Reduce (EMR)
8. Keyspaces
    Managed Cassandra (key value) with Some - CQL
9. Neptune
    Graph database with Some - openCypher
10. Timestream
    Time series database with Partial SQL support
11. Quantum Ledger
    Cryptographically verified transactions with Some - PartiSQL
12. Athena
    Ad-hoc queries on S3 with Some - CTAS. AWS Athena yazısına taşıdım
13. Babelfish
    MSFT SQL Server on Aurora with Full SQL support

Bir tablo şöyle

AWS Redshift yazısına taşıdım

Elastic Map Reduce (EMR)
Açıklaması şöyle
AWS excels at managing large amounts of data transformations at scale and with parallel processing.

Amazon EMR, Amazon Batch, and AWS Lambda are all suitable for this, each with its own purpose.

- Amazon EMR can be used if you want to dedicate a cluster to large data transformations.
- Amazon Batch can be used for large batch processes to scale up and down automatically.
- AWS Lambda can be used to execute custom data transformation in parallel at unmatched speed.







Mercator Projection

Haritaların Özellikleri
Açıklaması şöyle
Conformal
A conformal map projection preserves angles, in which any angle on a conformal map is true to their corresponding equivalent on Earth. If city A, city B and city C create a 60° angle at city B on a globe, this will be shown as such on a conformal projection. When we look for directions, we would want the 90° angle between road X and road Y in real life to also be portrayed as 90° on our map for easier navigation. This is not possible on a non-conformal map.

Equal area
As hinted by its name, an equal area projection preserves the sizes of areas as how they exist on the globe. It is therefore more reasonable to compare sizes of regions with an equal area map rather than with any other projection type, as it preserves landmass size most accurately. Shapes, however, will still be distorted.

Equidistant 
An equidistant map preserves distance, but only within a specific parameter. Some equidistant projections allow accurate distance measurement between two points on a meridian, which is the vertical line on our maps also known as a longitude (the equivalent of latitude, on the other hand, is called a parallel). Others require a central point, from which the distance is correctly measured. An equidistant map with London as its center, for example, accurately presents distances between London and any other point on the map, but not between Paris and Lisbon.

Compromise
Compromise map projections do not preserve any property and are therefore not appropriate for any calculation. However, they are the most suitable for general reference purposes compared to any of the previous types. A compromise map does not need to strictly maintain its accuracy, and as such, its priority is on reducing visual distortions to achieve landmass shapes as similar as possible as these on the globe.
Mercator Conformal Bir Harita
Açıklaması şöyle
Prior to Mercator’s chart, there was a strong chance of being lost during long distance sailings, especially across the ocean. Early sailing maps only displayed approximate sailing directions and rough distance measurements. These were not accurate, but often they covered small areas only, and thus their mistakes were rather inconsequential. This was extensively improved by Mercator. With his projection, seafarers would first mark their start and end point, and then connect these with a straight line. They would measure the angle between said line and any of the meridians it cuts through. Finally, upon sailing, they would only need to maintain this angle from their starting point until they arrived at their destination — all within the level of accuracy that was unheard of before. Needless to say, the Mercator projection revolutionized navigation.

Eleştiri
Mercator Avrupa'yı olduğundan büyük gösterir. Açıklaması şöyle
The immense distortion of the size of Europe and North America, leaving the rest of the world (often represented by Africa) seemingly small and powerless. 
Eğer ölçüleri tam görmek istiyorsak Gall-Peters Projection kullanılabilir.

19 Temmuz 2021 Pazartesi

GraphQL Schema

Giriş
Açıklaması şöyle. Schema tanımlama için kullanılan dile Schema Definition Language (SDL) deniliyor.
GraphQL has its own type system. This system is used to define the schema of an API. Basically, the syntax for writing schemas is known as Schema Definition Language or SDL.
Nesneler type Foo şeklinde tanımlanıyor. Alanların sonunda ! işareti varsa bu alan mecburidir anlamına geliyor. Yani es geçilemez. Açıklaması şöyle
The ! mark signifies that these are mandatory fields.

Örnek - String
Şöyle yaparız
type Query {
  shows(titleFilter: String): [Show]
}

type Show {
  title: String
  releaseYear: Int
}
Örnek - Int
Şöyle yaparız
type Employee {
  id: String!
  name: String!
  phone: String!
  age: Int!
}
Örnek - tehlikeli kod
Şu kod tehlikeli
type Query {
  album(id: ID!): Album
}
type Album {
  photos(first: Int): [Photo]
}
type Photo {
  album: Album
}

query maliciousQuery {
  album(id: ”some-id”) {
    photos(first: 9999) {
      album {
        photos(first: 9999) {
          album {
            photos(first: 9999) {
              album {
                #... Repeat this 10000 times...
              }
            }
          }
        }
      }
    }
  }
}

16 Temmuz 2021 Cuma

Golang

Giriş
2009 yılında Google tarafından geliştirilmeye başlandı. Yine Google tarafından geliştirilen Node.js'in rakibi. Bazı özellikleri şöyle

- C++ gibi bir standart kütüphaneye sahip
- Makine koduna derleniyor.
- Garbage Collection yapıyor.

Bir kitap burada

Go komutu
Örnek - get
Şöyle yaparız
go get solace.dev/go/messaging
Örnek - mod
Şöyle yaparız
mkdir funWithEDA && cd "$_"
go mod init GoEDA
Örnek - run
Şöyle yaparız
go run foo.go
Docker ve Golang
Örnek - multistage ve root olmayan kullanıcı
Şöyle yaparız
FROM golang:alpine3.15 as builder

WORKDIR /path
COPY . .

RUN go mod download
RUN go build -o "app" .

FROM alpine:3.15.5

WORKDIR /path

RUN apk update \
  && apk -U upgrade \
  && apk add --no-cache ca-certificates bash gcc \
  && update-ca-certificates --fresh \
  && rm -rf /var/cache/apk/*

RUN addgroup app_user && adduser -S app_user -u 1000 -G app_user

COPY --chown=app_user:app_user --from=builder /path/app .

RUN chmod +x /path/app

USER app_user

ENTRYPOINT ["/path/app"]
main metodu
Örnek
Şöyle yaparız
package main

import (
  "io"
  "net/http"
)

func main() {
  http.HandleFunc("/", helloWorld)
  http.ListenAndServe(":3000", nil)
}

func helloWorld(w http.ResponseWriter, r *http.Request) {
  io.WriteString(w, "Hello world!")
}
Import
Şöyle yaparız
package main

import (
  "fmt"
  "os"
  "os/signal"
  "strconv"
  "time"
  ...
)

func main() {
  ...
}
Import
Şöyle yaparız
package main
import (
 "net/http"
"github.com/labstack/echo/v4"
)
func main() {
  e := echo.New()
  e.GET("/", func(c echo.Context) error {
    var myarr [3]string
    myarr[0] = "Hello"
    myarr[1] = "From"
    myarr[2] = "GoLang"
    return c.JSON(http.StatusOK, myarr)
  })
  e.Logger.Fatal(e.Start(":8080"))
}

Fmt Paketi
Örnek - %v
Şöyle yaparız
fmt.Printf("Added %v %v \n", newPerson.first_name, newPerson.last_name)
Örnek
Şöyle yaparız
reader := bufio.NewReader(os.Stdin)

fmt.Print("Enter a first name: ")
firstName, _ := reader.ReadString('\n')
if firstName != "\n" {
  firstName = strings.TrimSuffix(firstName, "\n")
}
Time paket
Örnek
Şöyle yaparız
package main

import (
    "fmt"
    "time"
)

func say(s string) {
    for i := 0; i < 5; i++ {
        time.Sleep(100 * time.Millisecond)
        fmt.Println(s)
    }
}

func main() {
    go say("world")
    say("hello")
}
Değişken Tanımlama
Yeni değişkene ilk değer atama := ile yapılır. Sonradan değer arama = ile yapılır
Örnek
Şöyle yaparız
func main() {
  v1 := "some variable"
  var v2 = "some other variable"
  v1 = "now v1 has a different value"
  v2 = " same with v2"
  fmt.Print(v1, v2)
}
Pointers
Örnek
Şöyle yaparız
func main() {
  v1 := "some variable"
  // v2 is now a pointer to v1
  var v2 *string = &v1
  fmt.Print(v2) // prints the memory address of v1
}

Slices and maps
Örnek
Şöyle yaparız
func main() {
  v1 := []int{1, 2, 3}
  v1 = append(v1, 4)
 
  fmt.Println(len(v1)) // 4
  fmt.Println(v1[1])   // 2
  fmt.Println(v1[1:3]) // [2 3]
 
  v2 := make(map[string]string)
  v2["hello"] = "world"
 
  v3, ok := v2["hello"]
  fmt.Println(ok, v3)  // true world
}

Error Handling
Örnek
Şöyle yaparız
func test(input int) error {
  if input < 0 {
    return errors.New("less than zero")
  }
  return nil
}
func main() {
  err := test(-1)
  if err != nil {
    fmt.Print(err)
  }
}
Function Tanımlama
Typescript'e benziyor. func kelimesi ile başlıyor. Döndürülen tip en sona yazılıyor. Parametre tipleri de parametre isminden sonra geliyor.

Örnek
Şöyle yaparız. 
func someFunc(n int) int {
}
Interface ve Struct Tanımlama
Örnek
Şöyle yaparız
type Animal interface {
  Speak() string
}
type Dog struct {
  Name string
}
// here we define Speak as a method on Dog
// it takes a pointer receiver, but you 
// could also remove the *
func (d *Dog) Speak() string {
  return fmt.Sprintf("I am %s", d.Name) 
}
func main() {
  var dog Animal = &Dog{
    Name: "Cooper",
  }
 
  fmt.Println(dog.Speak())
}
Örnek - Struct
Şöyle yaparız
package main

import (
  "encoding/json"
  "net/http"
)

type ReqBody struct {
  Name string `json:"name"`
}

func main() {
  http.HandleFunc("/", HelloServer)
  http.ListenAndServe(":3000", nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
  var reqBody ReqBody
  json.NewDecoder(r.Body).Decode(&reqBody)
  w.Header().Set("Content-Type", "application/json")
  json.NewEncoder(w).Encode(reqBody)
}
pipeline
Blocking Queue gibidir
Örnek
Şöyle yaparız. "go foo" ile coroutine çalıştırılıyor. Yani Java karşılığı "Virtual Thread". "<-" ile de pipeline'a veri gönderiliyor ve veri okunuyor
package main

import "fmt"

func sum(s []int, c chan int) {
    sum := 0
    for _, v := range s {
        sum += v
    }
    c <- sum // send sum to c
}

func main() {
    s := []int{7, 2, 8, -9, 4, 0}

    c := make(chan int)
    go sum(s[:len(s)/2], c)
    go sum(s[len(s)/2:], c)
    x, y := <-c, <-c // receive from c

    fmt.Println(x, y, x+y)
}
Bunun Java karşılığı şöyle
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;

public class main {
  static void sum(int[] s, int start, int end, BlockingQueue<Integer> queue) 
  throws InterruptedException {
    
    int sum = 0;
    for (int i = start; i < end; i++) {
      sum += s[i];
    }
    queue.put(sum);
  }


  public static void main(String[] args) throws InterruptedException {
    int[] s = {7, 2, 8, -9, 4, 0};
    var queue = new ArrayBlockingQueue<Integer>(1);
    Thread.startVirtualThread(() -> {
      sum(s, 0, s.length / 2, queue);
    });
    Thread.startVirtualThread(() -> {
      sum(s, s.length / 2, s.length, queue);
    });
    int x = queue.take();
    int y = queue.take();

    System.out.printf("%d %d %d\n", x, y, x + y);
  }
}