简体   繁体   English

管理高流量连接应用程序的正确方法

[英]Right way to manage a high traffic connection application

Introduction 介绍

I am working on a GPS Listener, this is a service build on twisted python, this app receive at least 100 connections from gps devices, and it is working without issues, each GPS send data each 5 seconds, containing positions. 我正在使用GPS侦听器,这是基于双绞线python的服务,此应用程序至少从gps设备接收了100个连接,并且运行正常,每个GPS每5秒钟发送一次数据,其中包含位置。 ( the next week must be at least 200 gps devices connected ) (下周必须至少连接200 gps设备)

Database 数据库

I am using a unique postgresql connection, this connection is shared between all gps devices connected for save and store information, postgresql is using pgbouncer as pooler 我正在使用唯一的postgresql连接,此连接在所有用于保存和存储信息的gps设备之间共享,postgresql使用pgbouncer作为池

Server 服务器

I am using a small pc as server, and I need to find a way to have a high availability application with out loosing data 我正在使用一台小型PC作为服务器,并且我需要找到一种不丢失数据的高可用性应用程序的方法

Problem 问题

According with my high traffic on my app, I am having issues with memory data after 30 minutes start to appear as no saved, however queries are being executed on postgres ( I have checked that on last activity ) 由于我的应用流量很高,我在30分钟后开始显示内存数据出现问题,因为没有保存,但是查询是在postgres上执行的(我已经在上次活动中进行了检查)

Fake Solution 假溶液

I have amke a script that restart my app, postgres ang pgbouncer, however this is a wrong solution, because each time that I restart my app, gps get disconnected, and must to reconnected again 我使用了一个脚本来重新启动我的应用程序,postgres ang pgbouncer,但是这是一个错误的解决方案,因为每次我重新启动应用程序时,gps都断开连接,并且必须再次重新连接

Posible Solution 可能的解决方案

I am thinking on a high availability solution based on a Data Layer, where each time when database have to be restarted or something happened, a txt file store data from gps devices. 我正在考虑基于数据层的高可用性解决方案,其中每次必须重新启动数据库或发生某些情况时,txt文件都会存储来自gps设备的数据。

For get it, I am thing on a no unique connection, I am thinking on a simple connection each time one data must be saved, and then test database, like a pooler, and then if database connection is wrong, the txt file store it, until database is ok again, and the other process read txt file and send info to database 为了获得它,我是在没有唯一连接的情况下进行的,我正在考虑每次必须保存一个数据时都在一个简单的连接上,然后像缓冲池一样测试数据库,然后如果数据库连接错误,则将txt文件存储起来,直到数据库再次正常,其他进程读取txt文件并将信息发送到数据库

Question

Since I am thinking on a app data pooler and a single connection each time when this data must be saved for try to no lost data, I want to know 由于我在每次必须保存此数据以尝试不丢失数据时都在考虑应用程序数据池和单个连接,因此我想知道

Is ok making single connection each time that data is saved for this kind of app, knowing that connections will be done more than 100 times each 5 seconds? 知道每次将在5秒内进行100次以上的连接,每次为这种应用程序保存数据时是否可以进行单个连接?

As I said, my question is too simple, which one is the right way on working with db connections on a high traffic app? 如我所说,我的问题太简单了,在高流量应用程序上使用数据库连接的正确方法是哪一种? single connections per query or shared unique connection for all app. 每个查询单个连接或所有应用程序共享唯一连接。

The reason on looking this single question, is looking for the right way on working with db connections considering memory resources. 看这个单一问题的原因是,考虑到内存资源,正在寻找使用数据库连接的正确方法。

I am not looking for solve postgresql issues or performance , just to know the right way on working with this kind of applications . 我并不是在寻找解决postgresql问题或性能的方法 ,只是想知道使用此类应用程序正确方法 And that is the reason on give as much of possible about my application 这就是为什么要尽可能多地提供我的申请的原因

Note One more thing,I have seen one vote to close this question, that is related to no clear question, when the question is titled with the word "question" and was marked on italic, now I have marked as gray for notice people that dont read the word "question" 注意还有一件事,我看到一票赞成关闭这个问题,这与没有明确的问题有关,当该问题的标题为“ question”(问题)并用斜体标记时,现在我将灰色标记为注意人不要读“问题”一词

Thanks a lot 非常感谢

Databases do not just lose data willy-nilly. 数据库不仅会随意丢失数据。 Not losing data is pretty much number one in their job description. 在工作描述中,不丢失数据几乎是第一位的。 If it seems to be losing data, you must be misusing transactions in your application. 如果它似乎正在丢失数据,则必须在应用程序中滥用事务。 Figure out what you are doing wrong and fix it. 弄清楚您在做什么错并进行修复。

Making and breaking a connection between your app and pgbouncer for each transaction is not good for performance, but is not terrible either; 对于每个事务,在应用程序和pgbouncer之间建立和断开连接都不会提高性能,但也不是很糟糕。 and if that is what helps you fix your transaction boundaries then do that. 如果那是什么可以帮助您解决交易边界,那就去做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flask:关闭数据库连接的方式,是否能够处理高流量? - Flask: the way closing database connections, will it able to handle high traffic? 在 Python 3 中管理命名空间的正确方法是什么? - What is the right way to manage namespaces in Python 3? 在不重复连接部分的情况下,设计 Python / SQLite 应用程序的正确方法是什么? - What is the right way to design Python / SQLite application without repeating connection part? 在预分支守护程序中管理数据库连接的最佳方法是什么 - What is the best way to manage db connection in a preforking daemon 高流量站点的Dajaxice性能指标 - Dajaxice performance measures for high-traffic site 在python和Qt之间进行TCP连接的正确方法? - Right way to do TCP connection between python and Qt? 使用 pexpect 时关闭 ssh 连接的正确方法? - The right way to close ssh connection when using pexpect? 对于无法容纳在RAM中的训练集,在Theano中管理内存的正确方法是什么? - What is the right way to manage memory in Theano for training sets that cannot fit in RAM? 将python脚本添加到非python应用程序的“正确”方法 - The “right” way to add python scripting to a non-python application 如何以正确的方式为独立的 python 应用程序制作 setup.py? - How to make setup.py for standalone python application in a right way?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM