sysbench测试mysql性能瓶颈
myisam锁表机制

flask自动重连数据库

妙音 posted @ 2018年9月12日 07:43 in mysql with tags flask , 5079 阅读

情况描述

flask部署到服务器后,日志中经常出现错误
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2006, "MySQL server has gone away (ConnectionResetError(104, 'Connection reset by peer'))")
 
看下mysql日志,大量的超时导致的连接中断
...
2018-09-10  6:45:41 768 [Warning] Aborted connection 768 to db: 'xxx' user: 'xxx' host: '172.22.0.2' (Got timeout reading communication packets)
 

问题原因

原因就是因为连接超时,数据库把它中断了,详细参见官方文档.
https://dev.mysql.com/doc/refman/8.0/en/communication-errors.html
 

起因

  • 查看数据库配置。不要混淆全局配置与会话配置
show global variables like '%timeout%'

connect_timeout      5
interactive_timeout  28800
wait_timeout      600
 
  • 配置文件my.cnf
connect_timeout         = 5
wait_timeout            = 600
 

错误复现

mysql错误日志两次中断间隔时间都大于600秒,有可能是该参数引起,将它设置小点看看,能否复现问题
set global wait_timeout=10
 
设置后,问题又出现了,可以缺点就是该参数引起的。
 

自动重连实现

无论wait_timeou设置多大,总会出现超时,该怎么避免呢?简单方法是定时重连接.
 
flask已经提供了重连参数。连接超过一定时间就将它回收。
SQLALCHEMY_POOL_RECYCLE=7200   # 默认2小时。该值一定要比数据库wait_timeout小,否则它不起作用,上面就是这个原因导致的
 
当然这个方法不会帮我们处理网络异常导致的连接失效时重连
 
《了凡四训》详解之改过之法
印光大师十念法(胡小林主讲第1集)
此生必看的科学实验-水知道答案

 

Avatar_small
young thug hoodie 说:
2023年7月02日 19:55

The Real spider clothing, Hoodies, Bottoms, and Crewnecks young thug hoodie. Get amazing Spider Worldwide Clothing, Fast Shipping Shipping & Returns available.

Avatar_small
Imamia Quran Academy 说:
2023年7月27日 06:06

Your blog post deserves all of the positive feedback it’s been getting. I am from Imamia Quran Academy. The Shia Quran Madrassa online is a secure place for kids and adults to learn and memorize the Quran. They teach the real translation of the Holy Quran and the interpretation of the Holy Quran under the guidance of expert Quranic teachers.

Avatar_small
carson 说:
2023年8月25日 21:30

Garage door maintenance is essential to ensure it operates smoothly, safely, and efficiently. Proper maintenance can also extend the lifespan of your garage door and its components. Here are some steps you can take for garage door maintenance:

Maintaining your garage door is essential to ensure it operates smoothly, safely, and efficiently. Proper maintenance can also extend the lifespan of your garage door and its components. Here are some steps you can take for garage door maintenance:

Avatar_small
carson 说:
2023年8月26日 00:42

The Diy garage door stands as a remarkable testament to the fusion of functionality and aesthetics in modern architecture. Its sleek, yet robust design marries form and function seamlessly, enhancing the curb appeal of any home while serving as a guardian to the treasures within.

The garage door stands as a remarkable testament to the fusion of functionality and aesthetics in modern architecture. Its sleek, yet robust design marries form and function seamlessly, enhancing the curb appeal of any home while serving as a guardian to the treasures within.

Avatar_small
carson 说:
2023年8月26日 01:52

if you are looking for Garage door replacement you can visit our site and get new tips for replacement, ever we are also providing best of th best services about garage door.

Avatar_small
carson 说:
2023年8月26日 03:11

Garage door spring are a critical component of your garage door system. They counterbalance the weight of the door, making it easier to open and close. There are two main types of garage door springs

Avatar_small
carson 说:
2023年8月30日 01:22

The term "tec certificate" can refer to various certificates or credentials depending on the context. Here are a few possible interpretations

Avatar_small
carson 说:
2023年9月01日 06:25

In the digital age, email addresses are like digital fingerprints, leaving traces of our online presence wherever we go. While email is an indispensable tool for communication, it can also expose us to spam, privacy breaches, and the risk of personal information falling into the wrong hands. This is where temporary email generator come into play. In this article, we will delve into the world of temporary email generators, understanding what they are, how they work, and the advantages they offer in managing your online interactions.

Avatar_small
Best Pickleball Padd 说:
2023年9月05日 21:33

Choosing the best pickleball paddle is crucial for players looking to elevate their game. <a href="https://rapysports.com/best-pickleball-paddles-for-tennis-players/">Best Pickleball Paddles</a> are not one-size-fits-all; they come in various shapes, materials, and designs to cater to different playing styles and preferences. The ideal pickleball paddle strikes a balance between power and control, allowing players to make precise shots while delivering consistent performance.

Avatar_small
Best Pickleball Padd 说:
2023年9月05日 21:35

Choosing the [url=https://rapysports.com/best-pickleball-paddles-for-tennis-players/]Best Pickleball Paddles[/url] is crucial for players looking to elevate their game. These paddles are not one-size-fits-all; they come in various shapes, materials, and designs to cater to different playing styles and preferences. The ideal pickleball paddle strikes a balance between power and control, allowing players to make precise shots while delivering consistent performance.

Avatar_small
Best Pickleball Padd 说:
2023年9月05日 21:39

Choosing the [Best Pickleball Paddles](https://rapysports.com/best-pickleball-paddles-for-tennis-players/) is crucial for players looking to elevate their game. These paddles are not one-size-fits-all; they come in various shapes, materials, and designs to cater to different playing styles and preferences. The ideal pickleball paddle strikes a balance between power and control, allowing players to make precise shots while delivering consistent performance.

Avatar_small
carson 说:
2023年9月06日 04:22

The Essentials Hoodie for women redefines casual comfort with a touch of contemporary style. Designed to cater to the modern woman's wardrobe needs, this hoodie effortlessly blends fashion and function. Its thoughtfully crafted silhouette ensures a flattering fit while providing the relaxed coziness you seek in a classic hoodie. The minimalist yet chic design, adorned with essential elements like a kangaroo pocket and adjustable hood, offers versatility for various occasions. Whether you're pairing it with your favorite jeans for a relaxed day out or layering it over activewear for an athleisure look, the essentials hoodie women is a versatile staple that adapts to your lifestyle while maintaining an understated elegance. Crafted with attention to detail and constructed from quality materials, this hoodie is an embodiment of comfort and style that complements the dynamic nature of contemporary women's fashion.

Avatar_small
Tenniss sports Revie 说:
2023年9月07日 18:23

An SEO company in Albany, NY, plays a crucial role in helping businesses establish a strong online presence and reach their target audience effectively. With its expertise in search engine optimization (SEO) strategies and techniques, such a company can optimize a website's visibility on search engines like Google, Bing, and Yahoo. https://diginta.com/albany-seo-services/

Avatar_small
carson 说:
2023年9月09日 06:07

The influence of celebrities in fashion cannot be understated, and Vlone has gained significant attention thanks to endorsements from high-profile figures like A$AP Rocky himself, along with other artists and athletes. Their stamp of approval has further solidified Vlone Hoodies as a must-have item for those who want to channel the style of their favorite icons.

Avatar_small
Cruella costume 说:
2023年9月16日 19:51

What I find particularly exciting about Cruella de Vil cosplay is the opportunity to blend glamour and wickedness. Her signature black-and-white attire, complemented by her fiery personality, provides a rich canvas for creative expression. Your post not only highlights the key elements of her look, from the fur coat to the red gloves, but also offers valuable insights on achieving that authentic Cruella vibe.

Cosplay is all about embodying a character, and Cruella's larger-than-life presence makes her an exhilarating choice. Stepping into her stylish shoes, even for a short time, allows fans to embrace her confidence and flair.

Furthermore, your blog serves as a helpful resource for both beginners and experienced cosplayers, offering tips on where to find or create the various costume elements. The attention to detail and dedication to capturing <a href="https://cruelladevillecostume.com/">cruella deville cosplay</a> essence shine through in your post.

Thank you for sharing this informative and inspiring guide to Cruella de Vil cosplay. It's a reminder of the magic of transformation and creativity that makes cosplay such a vibrant and exciting subculture.

Avatar_small
tinkerbell dress 说:
2023年9月17日 02:33

What's so magical about Tinker Bell costumes is the opportunity they provide to embrace the spirit of this iconic fairy. From the shimmering green attire to the delicate wings, your post beautifully captures the essence of Tinker Bell's enchantment and offers valuable guidance on how to create an authentic costume.

Avatar_small
raposo frp 说:
2023年9月20日 02:23

这个问题看起来是由于MySQL连接超时引起的连接中断。你已经采取了一些措施来处理它,如设置wait_timeout和使用Flask的重连参数SQLALCHEMY_POOL_RECYCLE,这些都是有效的方法。确保SQLALCHEMY_POOL_RECYCLE的值小于数据库的wait_timeout,以确保它生效。如果网络异常也导致连接失效,你可能需要实现一些自动重连的逻辑,以处理这种情况。希望这可以帮助你解决这个问题!

Avatar_small
vape shop 说:
2023年9月20日 18:19

看起来你遇到了一个常见的问题,MySQL连接超时导致连接中断的情况。你的解释和配置方式都很清晰,感谢分享。使用SQLALCHEMY_POOL_RECYCLE参数来定时重连是一个不错的方法,确保它小于数据库的wait_timeout。这可以有效地解决一部分连接问题。

同时,你提到的网络异常导致的连接失效也是一个重要的考虑因素。在生产环境中,网络稳定性也很关键。如果网络异常是一个常见问题,你可能需要实施一些额外的措施来应对,例如使用连接池或实现自动重连机制,以确保应用程序在网络波动时能够恢复正常。

谢谢你分享有关MySQL连接问题的解决方案和参考链接!这对那些遇到类似问题的人来说将非常有用。

Avatar_small
xxxtentacion merch r 说:
2023年10月03日 18:08

XXXTentacion's "Revenge" merchandise collection is a testament to the enduring influence and emotional depth of the late rapper's music. Featuring a range of clothing and accessories, the Revenge merch incorporates bold and striking designs that often include the iconic "Revenge" logo in gothic lettering. This merchandise collection allows fans to not only express their admiration for XXXTentacion but also connect with the raw emotions and authenticity that characterized his work.

Avatar_small
xxxtentacion merch r 说:
2023年10月03日 18:09

XXXTentacion's "Revenge" merchandise collection is a testament to the enduring influence and emotional depth of the late rapper's music. Featuring a range of clothing and accessories, the Revenge merch incorporates bold and striking designs that often include the iconic "Revenge" logo in gothic lettering. This merchandise collection allows fans to not only express their admiration for XXXTentacion but also connect with the raw emotions and authenticity that characterized his work.

Avatar_small
Interpretation of dr 说:
2023年10月06日 20:43

Dream interpretation is a captivating field that delves into the mysterious world of our subconscious minds. It involves deciphering the symbolic language of our dreams to gain insights into our thoughts, emotions, and even our future. From ancient civilizations attributing dreams to divine messages to modern psychological approaches, dream analysis has evolved significantly.

Avatar_small
bbcode 说:
2023年10月17日 14:38

Wow! This could be one particular of the most useful blogs We have ever arrive across on this subject. Actually Magnificent. I am also a specialist in this topic so I can understand your effort.

Avatar_small
genericbucket02 说:
2023年11月01日 13:42

How to Use Iverheal 6

Iverheal 6 is a medication that has gained popularity in recent years due to its efficacy in treating various parasitic infections. This comprehensive guide aims to provide a detailed understanding of Iverheal 6, including its uses, benefits, potential side effects, and more. Whether you're a medical professional or a curious individual looking for information, this article is tailored to suit a larger audience.

Understanding Iverheal 6

Iverheal 6, an antiparasitic medication, is a member of the avermectin class of drugs. It contains 6mg of Ivermectin as its active ingredient, making it a valuable tool in combating parasitic infections. This medication is available in the form of oral tablets and is used to treat a variety of parasitic infestations, including strongyloidiasis, onchocerciasis, and scabies. It works by paralyzing and killing the parasites responsible for these conditions.

Key Uses of Iverheal 6

Strongyloidiasis Treatment:

Iverheal 6 is highly effective in treating strongyloidiasis, a parasitic infection caused by the nematode worm Strongyloides stercoralis. This condition often goes unnoticed for an extended period, making the accurate diagnosis and treatment with Iverheal 6 crucial.
Onchocerciasis Eradication:

Onchocerciasis, commonly known as river blindness, is a debilitating disease caused by the parasitic worm Onchocerca volvulus. Iverheal 6 is used to prevent the progression of this disease by killing the parasites responsible for it.
Scabies Management:

Scabies is a contagious skin condition caused by the Sarcoptes scabiei mite. Iverheal 6 is a viable treatment option for scabies and can provide relief from the intense itching and discomfort associated with this condition.

How Iverheal 6 Works

Iverheal 6 primarily exerts its antiparasitic effects through the active ingredient Ivermectin. Ivermectin works by disrupting the neural transmission in the parasites, leading to paralysis and eventual death. This mode of action makes it effective against various parasites, including nematodes and arthropods.

Benefits of Iverheal 6

Broad-Spectrum Efficacy:

Iverheal 6 is known for its broad-spectrum efficacy against a wide range of parasitic infections. This versatility makes it a valuable tool in regions where multiple parasitic diseases are prevalent.
Oral Administration:

The medication is administered orally, making it convenient and easy to use. This is particularly advantageous in regions with limited healthcare resources.
Preventive Measures:

Iverheal 6 is not only used to treat existing parasitic infections but also as a preventive measure in high-risk areas to control the spread of these diseases.
Minimal Side Effects:

When used as directed, Iverheal 6 is generally well-tolerated with minimal side effects. This is a significant advantage in populations with varying health conditions.

Potential Side Effects

While Iverheal 6 is considered safe and effective, it's essential to be aware of potential side effects, although they are generally rare and mild. Some possible side effects include:
Gastrointestinal symptoms such as nausea and diarrhea.
Dizziness and headache.
Skin rash and itching.
Mild fever.
It's crucial to consult a healthcare professional if any of these side effects persist or worsen.

Dosage and Administration

The dosage of Iverheal 6 may vary based on the specific condition being treated. It is essential to follow the prescribed dosage instructions provided by a qualified healthcare provider. The tablets should be taken on an empty stomach with a full glass of water to enhance absorption.

Transitioning Towards a Healthier Future

Iverheal 6 plays a significant role in the battle against parasitic infections, especially in regions where these diseases are endemic. It is not just a treatment but a stepping stone towards healthier communities. By eradicating parasitic infections, it helps improve the overall quality of life for those affected.

Ensuring Availability and Accessibility

Efforts are being made to ensure the availability and accessibility of Iverheal 6, especially in regions with a high prevalence of parasitic diseases. Various organizations and initiatives are working tirelessly to make this medication accessible to those who need it the most.

Iverheal 6, with its active ingredient Ivermectin, is a powerful tool in the fight against parasitic infections. Its wide range of applications, ease of administration, and minimal side effects make it a valuable asset in healthcare. This comprehensive guide has provided insights into its uses, benefits, potential side effects, and more. By understanding Iverheal 6, we move one step closer to a world free from the burden of parasitic infections.

In conclusion, Iverheal 6 has established itself as an important medication in the realm of global health, contributing to the well-being of countless individuals and communities worldwide. Its availability, efficacy, and minimal side effects underscore its significance in addressing parasitic infections, and its continuous usage promises a healthier and more prosperous future.

Avatar_small
carson 说:
2023年11月11日 00:48

FTP (Fuck The Population) clothes epitomize a fearless and defiant spirit within the world of street fashion. Known for their bold designs and unapologetic attitude, ftp clothes garments, including hoodies, shirts, and more, serve as a canvas for provocative graphics and edgy aesthetics. The iconic FTP acronym, boldly emblazoned on each piece, is a symbol of rebellion and non-conformity. Crafted with meticulous attention to detail, FTP clothes boast high-quality materials that prioritize both comfort and durability. Beyond being a mere ensemble, wearing FTP clothes is a deliberate choice to make a statement – a statement that challenges societal norms and embraces a countercultural mindset. The brand has successfully created a community that rallies around the ethos of authenticity and individual expression, turning FTP clothes into more than just garments but into symbols of a bold, subversive identity in the ever-evolving landscape of streetwear.

Avatar_small
carson 说:
2023年11月13日 05:07

BAPEstas can be purchased from bapesta shoes and authorized retailers around the world. They can also be purchased online from retailers such as StockX and GOAT.

Avatar_small
carson 说:
2023年11月14日 04:56

eric emanuel shorts are worn by people of all genders, races, ethnicities, and body types. The brand celebrates diversity and promotes inclusivity in all aspects of its business.

Avatar_small
ScarletApp.net 说:
2023年11月22日 18:43

Scarlet App is the epitome of cutting-edge mobile innovation, setting a new standard for user-centric experiences. With its sleek design and intuitive interface, Scarlet App redefines how users interact with their devices. This dynamic platform seamlessly integrates advanced features, offering unparalleled customization and performance.

Avatar_small
Rose 说:
2024年1月18日 23:05

<a href="https://www.xn--gpt-1n4o.co/">GPT 챗봇</a>
<a href="https://Chatgptdutch.org">Chat GPT Nederlands</a>
<a href="https://chatgptitaliano.pro/">chat gpt in italiano</a>

Avatar_small
Rose 说:
2024年1月18日 23:05

[url=https://www.xn--gpt-1n4o.co/]GPT 챗봇[/url]
[url=https://Chatgptdutch.org]Chat GPT Nederlands[/url]
[url=https://chatgptitaliano.pro/]chat gpt in italiano[/url]

Avatar_small
Dualari (dua) 说:
2024年4月16日 18:44

Dua, or prayer, holds a profound significance in the lives of believers across cultures and religions. It serves as a heartfelt conversation with the divine, a moment of surrender, gratitude, and supplication. Whether whispered in solitude or echoed in congregation, dua transcends boundaries, offering solace in times of distress and gratitude in moments of joy.

Avatar_small
Sonneriportable 说:
2024年5月03日 16:11

Sonneriportable offers completely free music and sounds that you can download! Access now


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter