Domain - Hosting - Reseller - Dedicated Server - Virtual Server - IRC Shell - Seedbox
Centos Dot Net Core Web Api Ram High Usage
Centos Dot Net Core Web Api Ram High Usage
-
Merhabalar,
Gecen gun yaptigimiz mobil projeyi yayina aldik.
40 user ile API server'in ram kullanimi %90 lara cikti. Ram artiyor surekli ve bosalmiyor. Monitor edip restart ediyorum cozum bulana kadar fakat bir cozum bulamadim 2 gundur uyumadim birseyi gozden kaciriyorum yardimci olursaniz cok sevinirim.
Hardware: 4 GB Memory / 80 GB Disk / 2 CPU - CentOS 7.4 x64
Software: c# dot net core 2.0.8 & mongo 3.6.2 visual studio communtiy for mac ile gelistirildi.Server: Nginx (proxy server)
Nginx configinde birsey atlamis olabilirim conf dosyasinda bir hata var mi sizce? API buludungu configuration location /appKestrel garbage collectorun calismadigindan supheleniyorum. Daha once kestrel ile is yapmadim fakat bu web server saniyede 1.2m istege yanit verebiliyor benchmark testlerindeki bilgiye gore.
GarbageCollection'un enabled olmadigini dusundum runtimeconfiguration.json olusturupGC.Server = true;
ile api'yi baslattim hic bir sey degismedi.
ApplicationInsights development icin data topladigini buldum disable etmek icin startup.cs yeTelemetryConfiguration.Active.DisableTelemetry = true;
ekledim yine birsey degismedi ram artmaya devam ediyor.
Startup.cs'de service sinifinlarini ioc ye singleton olarak ekliyorum. Ilk yayina cikarken AddTransient kullanmistim AddSingleton'a cevirdim birsey degismedi.services.AddSingleton<IMessageCollection, MessageCollection>();
ApiController constructoruna serviceleri new keywordu olmadan olusturuyorum.[Authorize, Route("api/[controller]")]
public class MessageController : Controller {
readonly IMessageCollection _messageCollection;
readonly IConfiguration _config;
public MessageController(IMessageCollection messageCollection, IConfiguration config) {
_messageCollection = messageCollection;
_config = config;
}
}
Context repository pattern'inde bir sorun olabilir mi :public class MongoContext {
public IMongoDatabase _database = null;
public MongoContext()
{
if (_database == null)
{
Console.WriteLine("database null connect mongo");
var client = new MongoClient($"{protocol}://{username}:{password}@{host}:{port}?authSource=admin");
if (client != null)
{
_database = client.GetDatabase(database);
}
else
{
throw new Exception("Mongo client can not be null. Check your connection string.");
}
}
}
public IMongoCollection<Message> Messages => _database.GetCollection<Message>("user");
}
public interface IMessageCollection {
Task<Message> GetByIdAsync(string id);
Task<Message> SaveAsync(Message entity);
Task DeleteAsync(string id);
Task<ICollection<Message>> FindAllAsync(Expression<Func<Message, bool>> predicate);
Task<Message> FindAsync(Expression<Func<Message, bool>> predicate);
Task<ICollection<Message>> PagingAsync(Expression<Func<Message, bool>> predicate, int offset, int limit);
Task<long> CountAsync(Expression<Func<Message, bool>> predicate);
}
public class MessageCollection : IMessageCollection {
readonly MongoContext _context = null;
public MessageCollection(){
_context = new MongoContext();
}
public virtual async Task<Message> GetByIdAsync(string id) {
return await _context.Messages.Find(x => x.Id.Equals(id)).FirstOrDefaultAsync();
}
}
dotnet --infoProduct Information:
Version: 2.1.200
Commit SHA-1 hash: 2edba8d7f1
Runtime Environment:
OS Name: centos
OS Version: 7
OS Platform: Linux
RID: centos.7-x64
Base Path: /usr/share/dotnet/sdk/2.1.200/
Microsoft .NET Core Shared Framework Host
Version : 2.0.7
Build : 2d61d0b043915bc948ebf98836fefe9ba942be11
Nginx.confuser nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
limit_req_zone $binary_remote_addr zone=one:10m rate=5r/s;
server_tokens off;
client_body_timeout 10;
client_header_timeout 10;
send_timeout 10;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
large_client_header_buffers 4 16k;
#include /etc/nginx/conf.d/*.conf;
server {
listen *:80;
server_name app.com;
add_header Strict-Transport-Security max-age=15768000;
return 301 https://$host$request_uri;
}
upstream io_nodes {
ip_hash;
server 127.0.0.1:10255;
}
server {
listen *:488 ssl;
server_name www.app.com app.com;
ssl on;
ssl_certificate /etc/ssl/app.com.bundle.crt;
ssl_certificate_key /etc/ssl/app.com.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on; #ensure your cert is capable
ssl_stapling_verify on; #ensure your cert is capable
add_header Strict-Transport-Security "max-age=63072000; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
client_max_body_size 20M;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_pass http://io_nodes;
}
}
server {
listen *:443 ssl;
server_name www.app.com app.com;
ssl on;
ssl_certificate /etc/ssl/app.com.bundle.crt;
ssl_certificate_key /etc/ssl/app.com.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on; #ensure your cert is capable
ssl_stapling_verify on; #ensure your cert is capable
add_header Strict-Transport-Security "max-age=63072000; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
client_max_body_size 20M;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location / {
proxy_pass http://localhost:5004;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /app {
rewrite /app/(.*) /$1 break;
proxy_pass http://localhost:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}#server
}#http
override tarafından 10/May/18 22:19 tarihinde düzenlenmiştir