24 Kasım 2021 Çarşamba

NewSQL Veri Tabanları

Giriş
Açıklaması şöyle
NewSQL is a class of relational database management systems that seek to provide the scalability of NoSQL systems for online transaction processing (OLTP) workloads while maintaining the ACID guarantees of a traditional database system.
Listede Vitess yok ancak bence o da dahil edilmeli. Vitess'in yerine kulanılabilecek TiDB listeye dahil edilmiş

23 Kasım 2021 Salı

Yazılım Mimarisi - Event Driven Architecture (EDA) With Event-Carried State Transfer pattern

Event-Carried State Transfer Pattern Nedir?
Açıklaması şöyle
As the name suggests, the main characteristic for the event-carried state transfer pattern is that the events contain state, which is quite different from notification events that just contain an identifier to retrieve state from the producer.
Örnek
Şöyle yaparız
{
  "specversion" : "1.0",
  "type" : "com.example.orderPlaced",
  "order" : {
    "id" : "A001-1234-1234",
    "time" : "2020-12-15T00:00:00Z",
    "products" : [{
      "id" : "1234321",
      "name" : "eBook Seven Languages in Seven Weeks",
      "price" : 25.00,
      "quantity" : 1
    }]
  }
}
Açıklaması şöyle. Burada önemli olan event'in içinde işlenmesi için gerekli alanların da olması. Böylece işleyen kod gidip tekrar çağrı yapıp bu bilgileri toparlamak zorunda kalmıyor
Including state in events eliminates the need for the consumer to make a call back to the producer to retrieve state. Instead, consumers build a private replica of state by storing the state from events they consume.
Yani tüketen taraf şu şekilde veri tabanına erişmek zorunda kalmıyor. Eğer üreten taraf zaten bu bilgiye sahipse, veri tabanına yapılan çağrılar azaltılabilir.
User user = userRepository.findById(event.getUserId());
Fat Event vs Delta Event
Açıklaması şöyle
In many publications an event that contains any state is referred to as a fat event. That would make all events that leverage the event-carried state transfer pattern fat events. Some authors, including myself, make distinctions between delta events and fat events. Delta events contain just the properties that changed, so just enough detail, nothing more.
Ne Zaman Kullanılmamalı
Eğe tüketen taraf verinin en son haline ihtiyaç duyuyorsa yani  Consumers require real-time accuracy gibi bir durum varsa  Event-Carried State kullanılmaz

22 Kasım 2021 Pazartesi

Grafana

Giriş
Açıklaması şöyle
Grafana is an open source solution for running data analytics, pulling up metrics that make sense of the massive amount of data & to monitor our apps with the help of cool customizable dashboards.
Grafana connects with every possible data source, commonly referred to as databases such as Graphite, Prometheus, Influx DB, ElasticSearch, MySQL, PostgreSQL etc
Açıklaması şöyle
Grafana is a tool that can inject various data sources and display them in a comprehensive graphical experience. It supports various data sources like ELK, Prometheus, Graphite. And It also supports sending alerts base on different conditions.
Prometheus
Grafana, Prometheus'un çıktısını dashboard tarzı daha okunaklı hale getirir. İlişkisi şeklen şöyle

Ekranları gösteren bir örnek burada

Data Source Ekleme
Data Source Ekleme yazısına taşıdım

grafana-server komutu
Grafana'yı başlatmak için "./bin/grafana-server" komutu çalıştırılır

Dashboard
Grafana Dashboard Genel Görünüm yazısına bakabilirsiniz
Grafana Dashboard Import yazısına bakabilirsiniz

Dashboard şöyle. Burada cluster için toplam CPU ve Memory kullanımı görülebilir

Container'lar için toplam CPU ve Memory kullanımı şöyle


Örnek - Create
 create -> Add Panel ile panel eklenir. Her panel'in metrics browser alanına birer birer şunlar eklenir
jenkins_plugins_active{}
jenkins_plugins_inactive{}
jenkins_plugins_failed{}
jenkins_plugins_withUpdate{}
Helm İle Kurulum
Şöyle yaparız
kubectl create ns prometheus
kubectl create ns grafana

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts

# deploy/prometheus-server diye deployment yapar
helm install prometheus prometheus-community/prometheus 
  --namespace prometheus 
  --set alertmanager.persistentVolume.storageClass="gp2" 
  --set server.persistentVolume.storageClass="gp2"

helm install grafana grafana/grafana 
  --namespace grafana 
  --set persistence.storageClassName="gp2" 
  --set persistence.enabled=true 
  --set adminPassword='EKS!sAWSome' 
  --values ./grafana.yaml 
  --set service.type=LoadBalancer

#get the DNS of grafana load balancer.
kubectl get svc -n grafana
Docker
Şöyle yaparız
docker pull grafana/grafana

docker run -d -p 3000:3000 grafana/grafana
"localhost:3000" adresine bağlanıtız. Kullanıcı ismi ve şifre "admin:admin"

Docker Compose
Docker Compose yazısına taşıdım

Kubernetes
Grafana Kubernetes Deployment yazısına taşıdım

Loki
Açıklaması şöyle
Grafana Loki is logging aggregation system which allows high available and multi tenancy.
In micro-service paradigm to read the logs from each micro-service is really hard when we do one by one. To identify one issue have to tail logs in multiple modules. But what loki does is support the log aggregation in single dashboard and will allow to query the results form dashboard.
Şeklen şöyle



promptail-config.yml şöyle. Logları loki'ye gönderir.
server: http_listen_address: 0.0.0.0 http_listen_port: 9080 positions: filename: /tmp/positions.yaml clients: - url: http://loki:3100/loki/api/v1/push scrape_configs: - job_name: docker entry_parser: raw pipeline_stages: - docker:{} static_configs: - labels: job: dockerlogs __path__: /var/lib/docker/containers/*/*log
promptail için docker plugin kurulmalı. Şöyle yaparız
docker plugin install grafana/loki-docker-driver:latest
  --alias loki --grant-all-permissions
loki-config.yml şöyle
auth_enabled: false

server:
  http_listen_port: 3100
  grpc_listen_port: 9096

common:
  path_prefix: /tmp/loki
  storage:
    filesystem:
      chunks_directory: /tmp/loki/chunks
      rules_directory: /tmp/loki/rules
  replication_factor: 1
  ring:
    instance_addr: 127.0.0.1
    kvstore:
      store: inmemory

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 24h

ruler:
  alertmanager_url: http://localhost:9093
Şöyle yaparız
version: "3"

networks:
  loki:

services:
  app:
    image: quiz-server:latest
    container_name: 'quiz-server'
    ports:
    - '8080:8080'
  loki:
    image: grafana/loki
    volumes:
      - /home/sajith/Documents/personal/blogs/grafana-loki/loki:/etc/loki
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/config.yaml
    networks:
      - loki

  promtail:
    image: grafana/promtail
    volumes:
      - /var/lib/docker/containers:/var/lib/docker/containers
      - /home/sajith/Documents/personal/blogs/grafana-loki/promtail/config.yml:/etc/promtail/config.yml
    command: -config.file=/etc/promtail/config.yml
    networks:
      - loki

  grafana:
    image: grafana/grafana:master
    ports:
      - "3000:3000"
    networks:
      - loki
Influx Veri Tabanı
Influx ile ilişkisi şeklen şöyle



20 Kasım 2021 Cumartesi

Machine Learning ve Overfitting - Öğrenme Yerine Ezber Yöntemini Kullanma

Overfitting Nedir?
Açıklaması şöyle
Overfitting, modelinizin öğrenme yerine ezber yöntemine geçmesine verilen isimdir. Aşırı öğrenme durumunu tespit etmek için en iyi yöntemlerden birisi; eğitim verisi dışında, ilk kez karşılaşacağı veriler ile modeli test etmektir. Eğitim verileri ile %90'ın üzerinde (hatta %100'e yakın) başarılı sonuç elde edebilirken harici veriler ile bu oran çok çok düşük olabilmektedir.
Overfitting problemini görsel olarak soran bir soru burada

Aşırı Öğrenmenin Önüne Nasıl Geçebiliriz?
Bazı önlemler burada

Önlem - Verileri Artırın
Açıklaması şöyle
If you're training a complex model with small amount of data, your model is very likely to overfit.
Örnek
Çözmek istediğimiz problem şu olsun
Imagine that you're building a model that predicts house price based on the floor area.
Elimizdeki veri şöyle olsun
area  price
30    100001
50    150002
80    200003
Problemin açıklaması şöyle
You train your model, then ask it to predict the price for a house of area=50, and it tells you that the price should be 150002. Is that impressively accurate? Not really. It's just memorizing the training data.
Overfitting is commonly detected through a large difference in performance between the training and test set. If you test on the training set, you're unable to detect overfitting.
Önlem - Aynı Veri Training ve Test İçin Kullanmayın
Bir örnek şöyle
As a teacher, you wouldn’t give your students an exam that’s got the exact same exercises you have provided as homework: you want to find out whether they (a) have actually understood the intuition behind the methods you taught them and (b) make sure they haven’t just memorized the homework exercises.

16 Kasım 2021 Salı

Global System for Mobile Communications Railway - GSM-R ve EIRENE ve MORANE Projeleri

Giriş
GSM-R yaratılırken EIRENE – MORANE projelerinden de girdi sağlanmıştır. 

IUC
IUC Fransızcası "Union internationale des chemins de fer" İngilizcesi "International Union of Railways" Türkçesi "Uluslararası Demiryolları Birliği"

IUC GSM Tabanlı Bir Sistem Oluşturmaya Karar Veriyor
1993 yılında IUC GSM Tabanlı Bir Sistem Oluşturmaya Karar Veriyor. Açıklaması şöyle
The UIC anticipated the need for a common wireless data frequency band and digital communications standard for border-crossing rail traffic, and so conducted a detailed technical and economical survey of digital technologies and, in 1993, decided to base the new system on GSM (Global System for Mobile Communications). This would ensure that railways could participate in the evolution of the public standard to include their specific needs. In addition, they might benefit from the economy of scale of the existing public market for the cost of their equipment.
Ancak standart GSM'in yetersiz kalacağını düşünüyorlar. Yetersizlikleri tanımlayacakları EIRENE isimli bir çalışma başlatıyorlar. EIRENE (European Integrated Radio Enhanced NEtwork) kısaltmasıdır. Yetersiz olduğunu düşündükleri noktalar şöyle
The decision to choose an open standard had some drawbacks, as not all specific requirements were covered by the GSM. Enhancements for special needs were necessary, which were researched and defined by the UIC’s ‘European Integrated Radio Enhanced Network’ (EIRENE) Project. The GSM system had to be modified to meet several types of features and requirements specific to railways, namely:

- Fast and guaranteed call set-up, (over all on emergency calls – maximum two seconds)
- Enable seamless communication for train speeds of up to 500km/h
- Functional addressing (e.g. a train number or coach number) for setting up a call and for display of calling/called party
- Location dependent functions, e.g. connection to the local ground
- Broadcast and group calls
- Priority and pre-emption mechanisms
- Set-up of urgent or frequent calls through a single keystroke or similar, including emergency call
- Train control European Rail Traffic Management System (ERTMS)
- Link assurance, an indication that the connection is maintained
- Automatic mobile network management
- Control over system configuration
- Automatic and manual test modes with fault indications
- Increased flexibility of operation through the use of SIM cards
Daha sonra bu EIRENE ve GSM-R sistemini deneyecekleri bir proje daha başlatıyorlar. Bu çalışmanın adı da MORANE. MORANE (MObile radio for RAilway Networks in Europe) kısaltmasıdır. 
The principal purpose of MORANE was to develop the GSM-R system in accordance with the EIRENE specifications and perform validation on three trial sites: SCNF, Deutsche Bahn, Ferrovie dello Stato
Açıklaması şöyle
In 1995, the UIC decided to establish a project to set up tests of the new system. Three railways, SNCF, DB, and Firenze SMN (Italy), set up the consortium ‘Mobile Radio for Railway Networks in Europe’ (MORANE) to conduct the trials. The overall aim of the project was to specify, develop, test, and validate the new GSM-R (GSM for Railways) system.
EIRENE Numbering Plan support
Aynı zamanda Functional Addressing de deniliyor. Alanlar şöyle.
IC International Code (also known as RAC-Railway Access Code, used for routing to the relevant GSM-R-Network)
CT Call Type (Identifies how to interpret the user number that follows)
UIN User Identifier Number. Call Type değerine göre yorumlanır
FC Function Code (used as an identification of f.e the person or equipment on a particular train, or a particular team within a given area)
Şeklen şöyle
Örnek
Example: connect to the train driver of train number 12345678 the following digits have to be entered:
• 2 (Call type, in this case it identifies the following number as a train number)
• 12345678 (UserIdentifierNumber, in this case "train number")
• 01 (Function Code, in this case "lead driver")
Yani çevrilen telefon numarası
2 12345678 01

GSM-R Numbering Plan
EIRENE tanımından gelen Call Type tablosu şöyle
Prefix Usage definition
0         Reserved for access to public or to other GSM-R networks
1         Reserved for short codes
2         Train Function Number
3         Engine Function Number
4         Coach Number
6         Maintenance and shunting team members
7         Train controllers
8         Mobile Subscriber Number
9         Reserved for breakout codes and national use
50       Group calls
51       Broadcast calls
52–55 Reserved for international use
56–57 Reserved for national use
58       Reserved for system use
59       Reserved for system use
0 ile başlayan numaralar Direct Call olduğu için mutlaka bağlanır
2,3,4,6,7,8,9 ile başlayan numaralar için Access Matrix kullanılır

Yani International Function Number şöyle
IC + CT + UIN + FC 
National Function Number şöyle
CT + UIN + FC 
Voice Group Call Ne Demek?
Çok sayıda kullanıcının aynı görüşmeye katılmasına izin verir.  Push To Talk gibi sadece bir tanesi konuşabilir.

Call Type Tipleri
Call Type 1 
Call Type 2
Call Type 3 
Call Type 4
Call Type 5
Call Type 6
var Açıklaması şöyle
• The Call Type (CT) prefix is used to distinguish between the different types of user numbers that are allowed within the national EIRENE numbering plan. It is an indication to the network of how to process the number dialed.
• The User Identifier Number (UIN) is the main identifier of, e.g., a train, a shunting team, etc.
• The Function Code (FC) is used as an identification of, e.g., the person or equipment on a particular train, or a particular team within a given area.

Call Type 1  - Kısaca Short Code
Call Type 1 için şöyle. Kısa yol içindir
Short Codes FC destination
1200  Signalman
1300  Regulator
1400  ECO
1500 ECP Extn (this role is a role which can take complete control of a specific Line                            Section thereby removing operational control from the Signalman)
1600 ECP Basic (this role is a role that shares access  to the radio network over a                                specific Line Section
1700 Signalman
1800 Network Loading
1900  Instruction
Call Type 2
Call Type 2 için şöyle. Tren içinde aramalar için kullanılıyor. Sanırım Call Type 2 için Function Code aslında "variable length" olabiliyor. Emin değilim.
Function Codes FC designation
01          Driver 1 (to be used for the Cab Radio)
02          Driver 2
07          Intercom
08          PA
10          Conductor
20          Catering
30          Security
99          Instruction
Call Type 3 
Call Type 3 için şöyle. Call Type 2 ile kesişen alanları var.
Function Codes FC designation
01          Driver 1
02          Driver 2
07          Intercom
08          PA
50          Train-borne recorder
Örnek
3 01011201 10 için Call Type = 3, User Identifier Number 01011201, Function Code = 10

Call Type 4 
Call Type 4 için şöyle. C
Function Codes FC designation
52          Train data bus
60          Pre-recorded passenger info
61          Displayed Passenger Info. Unit
Call Type 6
Call Type 6 "Shunting Team" içinde kullanılıyor. Calling Party şeklen şöyle

Mesela
6 85123 5 131
Call Type 6'dan önce başka rakamlar da olabilir. Eğer şeklen şöyle olursa
CgPa = <CC><NDC><GCRNumber><CT6 Number>
CdPa= <CallTypeAutomaticConference><Location Number starting with CT6ToVGSREFPrefixes><Function Code without team member function digit>

Calling Party= 41 512 940 6 85123 5 131
Called Party = 50 85 123501

Bazı Özellikler

1. Calling Line Identification Özelliği- CLIP
Beni arayan numarayı normalde SIM kartına ait telefon numarası ile görürüm. Eğer CLIP özelliği varsa telefon numarası yerine, arayan kişinin Functional Number numarasını görürüm.

2. Location Dependent Addressing Özelliği 
Açıklaması şöyle. Örneği "controller" aranmak istediğinde kullanılır
Location dependent addressing (LDA) is an effective and efficient addressing method in GSM-R (GSM for railways), which needs information on the location of the mobile station in order to forward the call to the correct called party.
Şeklen şöyle. Bir short code tuşlanır. 1200 gibi. 1 Call Type Short Code olduğunu belirtir. 200 ise Short Code numarasıdır


3. Access Matrix Özelliği
Şeklen şöyle.


4. Functional Number With Variable Length
Açıklama yaz

5. Follow me
Açıklama yaz

6. Delayed Deregistration
Açıklama yaz

7. Enhanced Railway Emergency Group Call
Kısaca eREC. Açıklayıcı bir video burada. Acil bir durumda kontrolör bir alan içindeki tüm trenleri arayıp, tam duruşa geçmelerini isteyebilir.

Redis Standalone Mode

Giriş
Açıklaması şöyle
What is a Single Redis Instance?

It’s a solution using the single Redis node deployment architecture.

Standalone Redis Pros:
- Simple and classical architecture.(Image 1)
- Easy deployment and configuration.

Standalone Redis Cons:
- It is not suitable for data reliability requirements.
- There is no backup(slave) node for real-time data synchronization.
- Because Redis is a single-threaded mechanism, its performance is limited by the processing capacity of a single-core CPU. The major bottleneck is the CPU, which restricts the number of instructions that can be performed on a single computer.
Şeklen şöyle


15 Kasım 2021 Pazartesi

Amazon Web Service (AWS) - Elastic Container Service - Docker İçindir

Giriş
Açıklaması şöyle. Docker Container gibi düşünülebilir. Container'lar halen EC2 üzerinde çalışır.
Elastic Container Service (ECS) and Elastic Container Service for Kubernetes (EKS) are container management services that support Docker containers and allow you to run applications on a managed cluster of Amazon EC2 instances. So there is no need to manage the infrastructure to deploy individual microservices.
Açıklaması şöyle. ECS Amazon'a mahsus bir çözümdür
Amazon ECS (Elastic Container Service) is a fully managed container orchestration service that allows you to easily deploy, manage, and scale Docker containers in AWS. It is an AWS-opinionated solution for running containers at scale, but organizations prefer ECS for the simplicity it provides.
Açıklaması şöyle
ECS allows you to use Network Access Control Lists (ACLs) and Amazon Virtual Private Clouds (VPCs) for resource isolation and security. Possibly one of the key features of ECS is that it is available in 69 availability zones and 22 regions globally, guaranteeing peace of mind regarding uptime, reliability, and low latency.
Şeklen şöyle