---
title: 后端连接优化
description: "在测试环境中，Nginx与Memcached之间的连接如果是短连接会导致Memcached主线程耗费大量时间分发连接给其他线程，主线程核占用会达到100%成为性能瓶颈。因此需要设置为长连接，减少主线程的开销，提升服务端整体性能。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengwebs/ecosystemEnable/Memcached/kunpengnginxmemcached_05_0016.html
sourcePath: /source/zh/kunpengwebs/ecosystemEnable/Memcached/kunpengnginxmemcached_05_0016.html
indexId: 4e687b3d8658bd3f6c12212cca0cb90120022d866679c39461f6871a0fb1177983
---
# 后端连接优化

在测试环境中，Nginx与Memcached之间的连接如果是短连接会导致Memcached主线程耗费大量时间分发连接给其他线程，主线程核占用会达到100%成为性能瓶颈。因此需要设置为长连接，减少主线程的开销，提升服务端整体性能。

在nginx.conf配置文件中的upstream模块添加keepalive配置。
```
upstream memcached_backend{
server 172.19.22.53:11211;
keepalive 500; }
```
