Skip to main content

Posts

Showing posts from August, 2024

Đọc code xem NGINX auto dùng bao nhiêu worker_processes trong container

NGINX là HTTP server phổ biến nhất trên thế giới. NGINX có kiến trúc "master" - "worker", với master process làm nhiệm vụ quản lý, và các worker process sẽ nhận các HTTP request và xử lý. NGINX worker_processes là gì Số lượng worker process được set bằng config directive: worker_processes mặc định là 1, và có thể "tự động" với từ khóa auto . Syntax: worker_processes number | auto; Default: worker_processes 1; Context: main Defines the number of worker processes. The optimal value depends on many factors including (but not limited to) the number of CPU cores, the number of hard disk drives that store data, and load pattern. When one is in doubt, setting it to the number of available CPU cores would be a good start (the value “auto” will try to autodetect it). The auto parameter is supported starting from versions 1.3.8 and 1.2.5. https://nginx.org/en/docs/ngx_core_module.html#worker_processes khi set auto , NGINX sẽ try to autodetect ...

Docker image alpine/curl không phải alpine

Nếu cần chạy 1 câu lệnh curl (hay http client khác để truy cập web API) trên container, dùng image nào nhẹ nhất? NOTE: thay podman bằng docker nếu dùng docker. alpine rồi cài curl alpine vốn phổ biến trong giới container vì nhẹ, nhưng không có sẵn curl, phải cài: $ podman run -it alpine sh -c 'apk add curl>/dev/null; curl https://www.openbsd.org/robots.txt' User-agent: * Disallow: /cgi-bin/ Disallow: /donations.html alpine/curl KHÔNG PHẢI alpine Google alpine curl xem image alpine nào cài sẵn curl? thấy ngay kết quả top alpine/curl , và dùng có vẻ thành công: $ podman run -it docker.io/alpine/curl sh -c 'curl https://www.openbsd.org/robots.txt' Trying to pull docker.io/alpine/curl:latest... Getting image source signatures Copying blob 9f444ea7cf45 done Copying blob 299588fda28b done Copying blob c6a83fedfae6 done Copying config d4f2de61cf done Writing manifest to image destination Storing signatures User-agent: * Disallow: /cgi-bin/ Disallow: /donations.ht...

Rust không import

Mọi ngôn ngữ lập trình hiện đại đều có cơ chế để dùng lại code. C có #include<stdio.h> thì Python, Go, Java có import . Rust không như thế, không có import, không cần import. Rust dùng thư viện bằng path đầy đủ Không cần import. Ví dụ sử dụng các function trong thư viện std::fs : fn main() { std::fs::create_dir_all("a/b/c/d").unwrap(); std::fs::write("a/file", "Hello").expect("Cannot write file"); let rd = std::fs::read_dir("a").unwrap(); for i in rd { let i = i.unwrap(); if i.path().is_dir() { println!("Directory {}", i.file_name().to_string_lossy()); } else if i.path().is_file() { println!("File {}", i.file_name().to_string_lossy()); } } } Code tạo thư mục a chứa thư mục b chứa thư mục c chứa thư mục d, tương tự lệnh mkdir -p a/b/c/d trên Linux. Sau đó ghi ra 1 file text tên "file" trong thư mục "a" dòng ch...

Popular posts from this blog

Tài liệu và hướng dẫn học Python

Để tiết kiệm thời gian, tốt nhất là đi học PyMI Updated: 130617 Sau đây là các tài liệu khuyên dùng: Vì nhiều lý do, nên học python2.7 tại thời điểm hiện tại (giờ là tháng 6/2013 - muốn biết tại sao thì tự tìm hiểu) python 3.5+ (giờ là tháng 2/2017) Chuẩn bị: 1. biết bật tắt máy 2. biết cài python 3. tập gõ 10 ngón - gõ 2 ngón hay 1 ngón cũng không sao, nhưng 10 ngón là cách dễ nhất để gõ nhanh nhất. Tài liệu - Nên dùng tài liệu tại trang chủ của Python làm chính, tham khảo thêm các tài liệu khác tại http://www.familug.org/2016/12/free-ebook.html Căn bản, mới học 1.1 Python PyMI.vn https://pymi.vn/tutorial/ 1.2. Python offical tutorial kết hợp làm bài tập trên HackerRank  (đề bài bằng tiếng Anh, nhưng Google translate 1 lúc cũng ra vì có nhiều ví dụ mẫu đi kèm). Học viên của Pymi.vn có rất nhiều học viên đã tự học với Learn Python the hard way nhưng chưa thấy ai thành công cả. Hai link dưới nên đọc sau khi đã nắm được những phần cơ bản của ngôn ngữ pytho...

The PyMiers

New FAMILUG