๐Ÿ“—
smiley book
  • Smiley Books
  • AI
    • Readme
    • openai-whisper
      • ์ƒ˜ํ”Œ ์‹คํ–‰ํ•ด๋ณด๊ธฐ
      • GPU ์„œ๋ฒ„ ์ค€๋น„ํ•˜๊ธฐ
      • API๋กœ whisper๋ฅผ ์™ธ๋ถ€์— ์˜คํ”ˆํ•˜๊ธฐ
      • ํ”„๋กฌํ”„ํŠธ ์ง€์›
      • ์‹ค์‹œ๊ฐ„ message chat
      • ํ™”๋ฉด ์ด์˜๊ฒŒ ๋งŒ๋“ค๊ธฐ์™€ ๋กœ๊ทธ์ธ
      • ํŒŒ์ด์ฌ ๊ฐ€์ƒํ™˜๊ฒฝ
      • ์‹ค์‹œ๊ฐ„ voice chat
      • fine tunning(๋ฏธ์„ธ ์กฐ์ •) ์œผ๋กœ ์„ฑ๋Šฅ ์˜ฌ๋ฆฌ๊ธฐ
      • app์—์„œ api๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์‹ค์‹œ๊ฐ„์œผ๋กœ ํ…์ŠคํŠธ๋กœ ๋ฐ”๊ฟ”๋ณด๊ธฐ
    • ollama - llm์„ ์‰ฝ๊ฒŒ ๋‚ด์ปด์—์„œ ์‹คํ–‰
      • ollama webui
      • ollama docker
    • stable diffusion
      • SDXL - text to image
      • SD-webui
    • ChatGPT
      • ๋‹ต๋ณ€์ด ๋Š๊ธธ๋•Œ
      • ์—ญํ• ์„ ์ •ํ•˜์ž
      • ๊ตฌ์ฒด์ ์ธ ์งˆ๋ฌธ
      • ๊ฒฐ๊ณผํ˜•ํƒœ๋ฅผ ์ง€์ •
      • ํ”„๋กฌํ”„ํŠธ๋ฅผ ์—ฌ๋Ÿฌ์ค„๋กœ ์‚ฌ์šฉํ•˜์ž.
      • ๋งˆํ‹ด ํŒŒ์šธ๋Ÿฌ ๊ธ€ ๋ฒˆ์—ญ๋ณธ
    • Prompt Engineering
    • Auto-GPT
    • Gemini
      • google ai studio
      • gemini-api
      • embedding guide
    • Huggingface
      • huggingface ์‚ฌ์šฉ๋ฒ•
      • huggingface nlp ๊ณต๋ถ€์ค‘
    • kaggle
      • download dataset
    • langchain
      • langchain์„ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ •๋ฆฌ
      • basic
      • slackbot
      • rag
      • document-loader
      • website-loader
      • confluence
      • memory
      • function-call
      • langsmith
      • agent-toolkit
  • Ansible
    • templates vs files and jinja2
    • dynamic inventory
    • limit ์˜ต์…˜ ๊ฐ•์ œํ•˜๊ธฐ
    • limit ์‚ฌ์šฉํ›„ gather_fact ๋ฌธ์ œ
  • AWS
    • AWS CLI
    • EKS
      • cluster manage
      • ALB Controller
      • external-dns
      • fargate
    • ECR
    • S3
    • Certificate Manager
  • Azure
    • Azure AD OAuth Client Flow
  • Container
    • Registry
    • ๋นŒ๋“œ์‹œ์— env๊ฐ’ ์„ค์ •ํ•˜๊ธฐ
  • DB
    • PXC
      • Operator
      • PMM
      • ์‚ญ์ œ
      • GTID
      • Cross Site Replication
    • Mssql
    • Mysql
  • dotnet
    • Thread Pool
    • Connection Pool
    • Thread Pool2
  • Devops
    • Recommendation
  • GIT
    • Basic
    • Submodule
  • GitHub
    • Repository
    • GitHub Action
    • GitHub PR
    • Self Hosted Runner
    • GitHub Webhook
  • GitLab
    • CI/CD
    • CI/CD Advance
    • Ssl renew
    • CI/CD Pass env to other job
  • Go Lang
    • ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ•
    • multi os binary build
    • kubectl๊ฐ™์€ cli๋งŒ๋“ค๊ธฐ
    • azure ad cli
    • embed static file
    • go study
      • pointer
      • module and package
      • string
      • struct
      • goroutine
  • Kubernetes
    • Kubernetes๋Š” ๋ฌด์—‡์ธ๊ฐ€
    • Tools
    • Install with kubespray
    • Kubernetes hardening guidance
    • 11 ways not to get hacked
    • ArgoCD
      • Install
      • CLI
      • Repository
      • Apps
      • AWS ALB ์‚ฌ์šฉ
      • Notification slack
      • Backup / DR
      • Ingress
      • 2021-11-16 Github error
      • Server Config
      • auth0 ์ธ์ฆ ์ถ”๊ฐ€(oauth,OIDC)
    • Extension
      • Longhorn pvc
      • External dns
      • Ingress nginx
      • Cert Manager
      • Kube prometheus
    • Helm
      • Subchart
      • Tip
    • Loki
    • Persistent Volume
    • TIP
      • Job
      • Pod
      • Log
  • KAFKA
    • raft
  • KVM
    • kvm cpu model
  • Linux
    • DNS Bind9
      • Cert-Manager
      • Certbot
      • Dynamic Update
      • Log
    • Export and variable
    • Grep ์‚ฌ์šฉ๋ฒ•
  • Modeling
    • C4 model introduce
    • Mermaid
    • reference
  • Monitoring
    • Readme
    • 0. What is Monitoring
    • 1. install prometheus and grafana
    • 2. grafana provisioning
    • 3. grafana dashboard
    • 4. grafana portable dashboard
    • 5. prometheus ui
    • 6. prometheus oauth2
    • Prometheus
      • Metric type
      • basic
      • rate vs irate
      • k8s-prometheus
    • Grafana
      • Expolorer
    • Node Exporter
      • advance
      • textfile collector
  • Motivation
    • 3 Simple Rule
  • OPENNEBULA
    • Install(ansible)
    • Install
    • Tip
    • Windows vm
  • Reading
    • comfort zone
    • ๋ฐฐ๋ ค
    • elon musk 6 rule for insane productivity
    • Feynman Technique
    • how to interview - elon musk
    • ๊ฒฝ์ฒญ
    • Readme
  • Redis
    • Install
    • Master-slave Architecture
    • Sentinel
    • Redis Cluster
    • Client programming c#
  • SEO
    • Readme
  • Security
    • criminalip.io
      • criminalip.io
  • Stock
    • robinhood-python
  • Terraform
    • moved block
    • output
  • vault
    • Readme
  • VS Code
    • dev container
    • dev container on remote server
  • Old fashione trend
    • curity
    • MAAS
      • Install maas
      • Manage maas
      • Tip
Powered by GitBook
On this page
  • Source code
  • entity framework sample code
  • ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด๋ณด์ž.
  • ํผํฌ๋จผ์Šค
  • todo

Was this helpful?

  1. dotnet

Connection Pool

PreviousThread PoolNextThread Pool2

Last updated 1 year ago

Was this helpful?

Thread Pool์— ์ด์–ด์ง€๋Š” ๊ธ€์ด๋‹ค.

Source code

entity framework sample code

๋‚˜๋Š” mysql๋กœ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. test๋””๋น„๋ฅผ ๋งŒ๋“ค๊ณ  blogํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์—ˆ๋‹ค ํ•ญ๋ชฉ์€ url์ด ํ•˜๋‚˜ ์žˆ๋‹ค.

dotnet add package Pomelo.EntityFrameworkCore.MySql --version 6.0.2
vi ValuesController.cs
using var connection = new MySqlConnection("server=192.168.1.21;User ID=root;Password=root;database=test;");
connection.Open();

using var command = connection.CreateCommand();
command.CommandText = "DO SLEEP(10);SELECT Url FROM Blogs;";

using var reader = command.ExecuteReader();
while (reader.Read())
{
  var url = reader.GetString(0);
  System.Console.WriteLine($"blog url {url}");
}

// Thread.Sleep(1000000); // Sleep for 10 seconds
Console.WriteLine("Thread completed. go back to the pool.");

์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  locust๋ฅผ ์‹คํ–‰ํ•˜์ž๋งˆ์ž ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค.

que๊ฐ€ ๊ณ„์† ์˜ฌ๋ผ๊ฐ„๋‹ค.

๋ฌธ์„œ์— ๋”ฐ๋ฅด๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ dbcontext๋Š” connection pool์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

AddDbContextPool๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ connection pool์€ 1024๊ฐœ์˜ ํ’€์„ ๋งŒ๋“ ๋‹ค. ์ด๊ฒƒ์€ ์„ค์ •์„ ํ†ตํ•ด์„œ ๋ณ€๊ฒฝํ• ์ˆ˜ ์žˆ๋‹ค.

ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ mysql์˜ max_connection ๊ฐฏ์ˆ˜๋ณด๋‹ค ๋งŽ์œผ๋ฉด thread๊ฐ€ ์ฃฝ๋Š”๊ฒƒ์„ ์•Œ์ˆ˜์žˆ๋‹ค

SHOW VARIABLES LIKE '%connect%';SHOW STATUS LIKE 'Threads_connected';

102๊ฐœ ์ด์ƒ์˜ ์ปค๋„ฅ์…˜์„ ์•ˆ๋ฐ›๋Š”๊ฑธ ์•Œ์ˆ˜ ์žˆ๋‹ค.

api๋Š” error๋ฅผ ๋ณด๋‚ธ๋‹ค.

api๋ฅผ ๋ฉˆ์ถ”์ž.

๊ทธ๋Ÿฌ๋‚˜ ํ˜„์žฌ ์—ฐ๊ฒฐ๋œ ๊ฐฏ์ˆ˜๋Š” ์ค„์–ด๋“ค์ง€ ์•Š๋Š”๋‹ค.

์ด๊ฒƒ์€ mysql์˜ wait_timeout์ด 8์‹œ๊ฐ„์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. 8์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด ์ค„์–ด๋“ค๋ ค๋‚˜.

๊ฒฐ๊ณผ์ ์œผ๋กœ connect์„ ๊ณ„์† ๋Š˜๋ฆฌ๋ฉด ๋ฌธ์ œ๊ฐ€ ๋œ๋‹ค. ๋””๋น„๋ฅผ ์žฌ์‹œ์ž‘ํ•ด์•ผํ•˜๋Š”๊ฒฝ์šฐ๊นŒ์ง€ ์ƒ๊ธธ์ˆ˜ ์žˆ๋‹ค.

์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด๋ณด์ž.

// command.CommandText = "DO SLEEP(1000);SELECT Url FROM Blogs;";
command.CommandText = "SELECT Url FROM Blogs;";

๋ฌธ์ œ์—†์ด ๋ชจ๋“ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ• ์ˆ˜ ์žˆ๊ณ  connect๋„ ๋งŽ์ด ์ถ”๊ฐ€๋˜์ง€ ์•Š๋Š”๋‹ค

๊ฒฐ๋ก ์€ ์ฟผ๋ฆฌ๊ฐ€ ๋๋‚˜๋ฉด ์ปค๋„ฅ์…˜์ด ์ž๋™์œผ๋กœ ๋Š์–ด์ง€๋Š”๊ฑธ ์•Œ์ˆ˜์žˆ๋‹ค.

์ปค๋„ฅ์…˜ ํ’€์„ ์‚ฌ์šฉํ•˜๋ฉด ์ปค๋„ฅ์…˜์„ ์žฌ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๊ณ  ์ปค๋„ฅ์…˜์„ ๋” ๋นจ๋ฆฌ ์–ป์„์ˆ˜ ์žˆ๋‹ค.

ํผํฌ๋จผ์Šค

๋‘๋ฐฐ ์ด์ƒ์˜ ์ปค๋„ฅ์…˜ ๋งบ๋Š” ์†๋„ ํ–ฅ์ƒ์„ ์–ป์„์ˆ˜ ์žˆ๋‹ค.

todo

๋‹ค์Œ์€ redis๋ฅผ ํ•ด๋ณด์ž.

https://github.com/teamsmiley/gitbook-sample/tree/main/ThreadTest
https://learn.microsoft.com/en-us/ef/core/performance/advanced-performance-topics?tabs=with-di%2Cexpression-api-with-constant#dbcontext-pooling
alt text
alt text
alt text
alt text
alt text
alt text