Tile improved on its ultra-popular device trackers by adding waterproofing, customizable ring tones, increased range, and a more durable design to its new Pro series. At just $18 each, you can get four Tile Sports, while they last.
Or How ProxySQL Out-performs Native Aurora Cluster Endpoints
In this blog post, I’ll look at how you can use ProxySQL with AWS Aurora to further leverage database performance. My previous article described how easy is to replace the native Aurora connector with ProxySQL. In this article, you will see WHY you should do that. It is important to understand that aside from the basic optimization in the connectivity and connection management, ProxySQL also provides you with a new set of features that currently are not available in Aurora. Just think:
Better caching
Query filtering
Sharding
Query substitution
Firewalling
… and more
We will cover areas like scalability, security and performance. In short, I think is more than worth it to spend some time and give ProxySQL with AWS Aurora a try.
The tests
I will show you the results from two different kinds of tests. One is sysbench-oriented, the other simulates a more complex application using Java, data object utilization and a Hikari connection pool in the middle as well. For the EC2 and Aurora platform I used:
Application/ProxySQL T2.xlarge eu-central-1a
2 Aurora MySQL 5.7.12 db.t2.medium eu-central-1a
1 Aurora MySQL 5.7.12 db.t2.medium eu-central-1b for AZ redundancy
The code for the application is available here, and for sysbench tests here. All the data and configurations for the application are available here.I ran three tests using both bench apps, obviously with Aurora as it comes and with ProxySQL. For the ProxySQL configuration see my previous article. The tests were read_only / Write_only / read_write. For Aurora, I only increased the number of connections and kept the how it comes out of the box approach. Note each test was run at least three times at different moments of the day, and on a different day. The data reported as final is the BEST performing result for each one.
The Results
For the impatient among us, here is a summary table of the tests:Sysbench:
Java App:
Now if this is enough for you, you can go to the conclusion and start to use ProxySQL with AWS Aurora. If you would like to know a bit more, continue reading. Aside from any discussion on the benchmark tool and settings, I really focused on identifying the differences between the two “connectors”. Given the layer below was exactly the same, any difference is due to the simple substitution of the endpoint.
Sysbench
Read Only
The first image reports the number of events achieved at the time of the test. It is quite clear that when using ProxySQL, sysbench ran more events. In this graph, higher is better: In this graph, lower is better:
As we can see, the latency when using an Aurora cluster entry point is higher. True, we are talking about milliseconds, but it is not just the value that matters, but also the distribution:
Aurora cluster endpoint
ProxySQL
An image is worth a thousand words!We can see, the behavior stays constant in analyzing the READS executed, with ProxySQL performing better.
In this graph, higher is better:
In this graph, higher is better:
Closing with the number of total queries performed, in which ProxySQL surpassed the Cluster endpoint by ~ 4K queries.
Write Only
For writing, things go a bit different. We see that all lines intersect, and the values are very close one to the other.
I will let the images speak for themselves:
In this graph, higher is better:
In this graph, lower is better:
Latency spiked in each ProxySQL test, and it may require additional investigation and tuning.
In this graph, higher is better:
While the rates of writes/sec intersect with each other frequently, in the end ProxySQL resulted in more writes than the native endpoint.
In this graph, higher is better:
In the end, a difference exists and is consistent across the different test iterations, but is minimal. We are talking a range of 25 – 50 entries in total.
This result is not surprising, and it will be clear why later in the article.
Read and Write
As expected in the read and write test, we see a different situation.
ProxySQL is still performing better than the default entry point, but not by such a big margin as in read-only tests.
In this graph, higher is better:
In this graph, lower is better
Latency and events are following the expected trend, where read operations are executed more efficiently with ProxySQL and writes are close, but NOT the same as in the write only test.
As a result, the number of queries in ProxySQL is approximately 13% better than the default entry point.
Java Application Tests
What about the Java application? First of all, we need to remember that the application used a connection pool mechanism (Hikari), and the connection pool was present in all cases (for both Aurora cluster endpoint or ProxySQL). Given that a small delay in establishing the first connection was expected, you can easily see this in the MAX value of the connection latency. In this graph, lower is better.
The connection latency reported here is expressed in nanoseconds and is the measure of the time taken by the connection provider to return an active connection to the application from the moment the application requested it. In other words, how long the HikariCP is taking to choose/check/return an open connection. As you can see, the MAX value is drastically higher, and this was expected since it is the connection initialization. While not really interesting in terms of performance, this value is interesting because it gives us the dimension of the cost in the CP to open a new connection, which in the worse case is 25 milliseconds. As the graphs show, ProxySQL manages both cases (first call, reassignment) more efficiently. In this graph, higher is better.
In the CRUD summary table, we can see the number of SQL commands executed per second for each CRUD action and for each test. Once more we can see that when using ProxySQL, the application performed much better and significantly executed more operations (especially in the R/W test).
In this graph, higher is better.
This graph represents the total number of events run at the time of the test. An event is a full application cycle, which sees the application generate the data needed to fill the SQL (no matter if it is for read/write), create the SQL, request the connection, push the SQL, get and read the resultset returned and give back the connection. Once more, ProxySQL shows better performance. In this graph, lower is better.
The execution time reported in this graph is the time taken by the application to run a whole event. This is it, execution time is the time of a full cycle. The faster the cycle is executed, the better the application is performing. The time is express in milliseconds and it goes from a very fast read, which probably accesses the cache in Aurora, to almost two seconds taken to insert a batch of rows.Needless to say, the tests using ProxySQL performed better.
But Why?
Why do the tests using ProxySQL perform better? After all, it is just an additional step in the middle, which also has a cost in intercepting the queries and managing the connections.
That endpoint receives the read and write request and sends them to the same instance.The main use for it is to perform failover if needed. At the same time, the Reader endpoint is an endpoint for an Aurora DB cluster that connects to one of the available Aurora Replicas for that DB cluster.
Each Aurora DB cluster has a reader endpoint. If there is more than one Aurora Replica, the reader endpoint directs each connection request to one of the Aurora Replicas. The reader endpoint only load balances connections to available Aurora Replicas in an Aurora DB cluster. It does not load balance specific queries.
If you want to load balance queries to distribute the read workload for a DB cluster, you need to manage that in your application and use instance endpoints to connect directly to Aurora Replicas to balance the load. This means that to perform a Read/Write split, your application must manage two entry points and you will NOT have much control over how the queries are handled or to which replica instance they are directed.
This could lead to unexpected results and delays. Needless to say, ProxySQL does all that by default (as described in my previous article).Now that we’ve clarified how Aurora entry points behave, let’s see about the performance difference.
How do we read this graph? From left to right:
read_only test with an Aurora cluster endpoint
read_only test with ProxySQL
write_only with an Aurora cluster endpoint
write_only with ProxySQL
read and write with an Aurora cluster endpoint
read and write with ProxySQL
Here we go! As we can see, the tests with ProxySQL used the two configured instances, splitting R/W without the need to do anything on the application side. I purposely avoided the AZ replica because I previously identified it as having higher latency, so I can exclude it and use it ONLY in the case of an emergency.
The effects are clear in the next graph.
When using the cluster endpoint, given all the load was on a single instance, the CPU utilization is higher and that became a bottleneck. When using ProxySQL, the load is spread across the different instances, allowing real read scalability. This has immediate benefits in read and read/write operations, allowing better load distribution that results in better performance.
Conclusions
Aurora is a very interesting technology and can be a very good solution for read scaling. But at the moment, the way AWS offers data connectivity with the Cluster endpoints and Reader endpoints can negatively affect performance.
The lack of configuration and the limitation of using different endpoints lead to confusion and less optimized utilization.
The introduction of ProxySQL, which now supports (from version 2) Aurora, allows an architect, SA or DBA to properly configure the environment. You can very granularly choose how to use each instance, without the need to have the application modify how it works. This helps keep the data layer solution separate from the application layer. Even better, this additional set of flexibility does not come with a cost.
On the contrary, it improves resource utilization and brings higher performance using less powerful instances. Given the cost of Aurora, this is not a secondary benefit.
I suggest you try installing ProxySQL v2 (or higher) in front of your Aurora cluster. If you don’t feel confident and prefer to have us help you, contact us and we will be more than happy to support you!
Americans are ingenious.That’s a well-known fact.Take just one look at the history of arms development in this country and it becomes easy to see what I’m talking about. As a wise man once said, you can’t stop the signal. Where there’s a will, there’s a way. You’d think the California gun-grabbers would have figured that out by now, but I guess not.
What’s one of the easiest ways to get around the definition of a so-called “assault weapon” without having to remove your collapsible stock, pistol grip, flash hider, etc? Give your AR-15 a fixed, 10-round magazine. If it doesn’t detach or hold more than 10 rounds, you’re in the clear. (Makes sense, right? Don’t answer that.)
So, that’s exactly what CompMag did. The way it works is simple. Remove your upper receiver and insert the CompMag in your magwell. Next, put the supplied plate over the screw hole in the mag. Then, attach the mag to the magwell with the screw provided. (They even provide a tube of threadlocker.) Boom, you’re done. Now you’ve got a rifle with a fixed, 10-round magazine. You can hit the mag release as hard or as often as you want; it isn’t going to budge.
Installation was a breeze. Thankfully, I don’t live in a state that requires such silliness, so I opted not to use the threadlocker when testing, which would have created a “permanent solution.” Even so, using it would have only slowed me down by a matter of seconds.
But how do you load it? Once again, the operation is simple. A cover on the side of the unit slides down to provide access to the magazine’s internals. Pushing down a lever and locking the knob under the lip compresses the spring and allows you to load the mag. Simply insert 10 rounds into the mag, close the cover, and release the spring tension. You’re inserting the rounds at the bottom of the fixed portion of the mag, which means that each round thereafter gets pushed up into the internal cavity.
As a bonus, there’s even a round counter on the side that keeps track via the knob as it moved up in the mag.
Function testing couldn’t have been easier. Well, I guess it could have been if the mag fell free and I could slap another one in right away, but considering the circumstances, it was easy. When the bolt locked open after the tenth round, I just slid open the cover on the side of the mag and fed ten more rounds into it. I didn’t experience any issues with feeding, ejecting, locking open, etc.
When it comes down to it, the CompMag is a brilliant – and simple – solution to an annoying problem. Would it be better if California quit infringing on citizens’ rights? Absolutely. Is that ever going to happen? Good question. Until then, buy a CompMag or move out of the state!
Good news for AK owners: a CompMag for your gun is in the works!
Ratings (out of five stars):
Quality: * * * * * Everything is high-quality and American-made in California. The company didn’t skimp on any aspect of the design or build of the product.
Ease of Use: * * * * * Installation and loading of the CompMag is completely idiot-proof.
Value: * * * * At $64.99, the CompMag isn’t exactly cheap. Nonetheless, it is an all-American product and I’m sure it wasn’t cheap to develop, patent, and produce it. At the end of the day, can you really put a price on being able to keep your AR in California? (Again, don’t answer that.)
Overall: * * * *
It sucks that some people have to go to such lengths to keep their AR-15s, but this product makes it suck a little less. It’s super easy to use and incredibly well made. If you find yourself in a situation where you need something like this, I’d definitely recommend it. The price point is the only thing keeping it from a full five stars in my book.
In my previous blog post, I showed how we could load into any metrics, benchmarks into MySQL and visualize it with PMM. But that’s not all! We can even visualize most any kind of data from MySQL in real time. I am falling in love with the MySQL plugin for Grafana — it just makes things so easy and smooth.
This graph shows us the number of visitors to a website in real time (refreshing in every 5 seconds).
We store the number of visitors every second. I am not saying you have to update this table hundreds or thousands of times, it depends on how many visitors you have. You could use the example of Redis to store and increase this counter and save it into MySQL every second. Here are my metrics:
We can easily add my MySQL query to Grafana, and it will visualize it for us:
You might ask “what is $__timeFilter?” I discussed that in the previous post, but let me copy the manual here as well:
Time series:
- return column named time_sec (UTC in seconds), use UNIX_TIMESTAMP(column)
- return column named value for the time point value
- return column named metric to represent the series name
Table:
- return any set of columns
Macros:
- $__time(column) -> UNIX_TIMESTAMP(column) as time_sec
- $__timeFilter(column) -> UNIX_TIMESTAMP(time_date_time) ≥ 1492750877 AND UNIX_TIMESTAMP(time_date_time) ≤ 1492750877
- $__unixEpochFilter(column) -> time_unix_epoch > 1492750877 AND time_unix_epoch < 1492750877
- $__timeGroup(column,'5m') -> (extract(epoch from "dateColumn")/extract(epoch from '5m'::interval))::int
Or build your own conditionals using these macros which just return the values:
- $__timeFrom() -> FROM_UNIXTIME(1492750877)
- $__timeTo() -> FROM_UNIXTIME(1492750877)
- $__unixEpochFrom() -> 1492750877
- $__unixEpochTo() -> 1492750877
What can I visualize?
It’s true! Basically, if you can write a query, you can graph it. For example, let’s count all the visitors in every minute. Here is the query:
select
UNIX_TIMESTAMP(ps.time) as time_sec,
sum(visitors) as value,
'visitors' as metric
from
page_stats as ps
WHERE $__timeFilter(time)
GROUP BY DATE_FORMAT(`time`, '%Y-%m-%d %H:%i')
ORDER BY ps.time ASC;
And it gives us the following graph:
See, it’s easy!
Conclusion
There is no more excuse why you can not visualize your data! Percona Monitoring and Management lets you plot MySQL data in real time. You do not have to move it anywhere or change anything! Just grant read access from PMM, and you can start to create your own graphs!
In this episode of TFBTV, James gives the Sig Sauer P365 in 9mm a thorough rundown. On paper, the P365 looks like the ultimate carry 9mm: it’s as thin and light as most single stack 9mm pistols that only carry 6 or 7 rounds, while it can hold up to 11 (or 13 rounds with […]
It was a dangerous week for some of the biggest names in technology as they they were forced to face off against these new things called "consequences" which have come about due to their ongoing "actions." It’s all so very unfair. Ashley Madison is still super duper sorry about the whole exposing of America’s least competent infidelitors thing, Reddit is saying "sayonara" to bitcoin (but not its resident racists), and the government of Ecuador went and changed up the Wi-Fi password on poor Julian Assange. But hey, at least Zuck won’t be out of a job anytime soon. Numbers, because how else will we know whether she’ll sink or float?
18 years: The wheels of justice turn slowly, even when they’ve gone off the rails. Adnan Syed spent nearly two decades in a cell for a crime he reportedly didn’t commit. But, thanks to some sterling reporting from the producers of the Serial podcast, Mr. Syed has been awarded a new trial by the state of Maryland.
136,000 data points, I mean "people": In the wake of the Cambridge Analytica scandal, the data collection company promised that it would "delete" all of the data it had acquired. Yeah, just like I’m going to "stop drinking" and "get my shit together". Channel 4 just discovered a cache of data from 136,000 Colorado residents, including their personality profiles, which is just wow. So, if you haven’t deleted your Facebook profile yet, now would probably be a good time to do so before that information leaks and the internet gets to play head shrinker with your most personal of datas.
30 million exposed accounts: The team behind the voluntary adultery site, Ashley Madison, is somehow back, having clearly not learned their lesson. After being fined more than $12 million, the site is still online and attracting a new crop of philanderers with its new slogan, "Find your moment". That has such a nicer ring than "Life is short. Have an affair," doesn’t it.
1,099,511,627,776 combinations: So the Ecuadorian embassy has apparently had enough of Julian Assange’s shenanigans and has revoked his internet access. All Big Jules has to do is guess the right 16-digit character combination and he can get right back to helping subvert US elections. Granted, it’s going to potentially take slightly more than a trillion tries, but what else are you going to do while trapped in a downtown London closet with nothing but time on your hands?
0 repercussions: Mark Zuckerberg has built a global data mining operation and somehow convinced us all that it’s worthwhile. His company has facilitated meddling with the US political system and given the Winklevoss twins 14 minutes more spotlight than they deserve. His penance for these sins, of course, will be to remain one of the richest people on Earth.
4/22: I’ve never actually watched "Westworld" so I’m going to go ahead and just assume its just robotic witches fighting robosamurai like from this trailer for the second season which I also didn’t watch.
An anonymous reader writes:
Google, Qualcomm, and Samsung "are among 80 tech companies joining forces to develop a new open-source chip design for new technologies like self-driving vehicles," writes Seeking Alpha, citing a (pay-walled) report on The Information. "Western Digital and Nvidia also plan to use the new chip design for some of their products," while Tesla "has joined the RISC-V Foundation and is considering using the tech in its new chip efforts."
MIT Technology Review adds that while Arm had hoped to bring their low-power/high performance processors to AI and self-driving cars, "The company that masterminded the processor inside your smartphone may find that a set of free-to-use alternative designs erode some of its future success."
Whether you’ve been dreaming about space all your life, or just like the idea of a car on its way to Mars, there’s no denying that space exploration continues to be a fascination for many.
While joining the NASA engineering team may be impossible for most, these backyard space projects have all been produced in the homes, garages, and gardens of amateur rocket engineers and enthusiasts. 3… 2… 1… lift off!
This incredible mission control desk was built by Jeff Highsmith from Make. Using a variety of switches, knobs, lights, and dials, this incredible project looks and sounds just like the real thing.
Using an iPad to play space videos, and a Raspberry Pi in conjunction with an Arduino, all of the controls actually work. With factually accurate labels for oxygen levels, altitude, speed, and more, there’s not much you can’t do.
In addition to the cool buttons, Jeff programmed simulations of real historical space glitches, complete with accurate solutions! Unfortunately, this desk doesn’t control a real spaceship—but there’s no reason it couldn’t with a bit of re-programming.
When Apollo 11 landed on the Moon in 1969, the astronauts left something bigger than footprints behind. The surface of the moon contains a 2 foot wide panel covered in 100 mirrors. By using a laser and several pieces of sensitive electronics, you can fire a laser at the moon, bounce it off the mirror array, and detect the returning beam.
Admittedly, you’ll need a very powerful laser, a large telescope, and some specialist equipment, but there’s nothing stopping you renting time in a local observatory. You won’t be able to reuse your old laser pointer 6 Uses For An Old Laser Pointer
The premise is simple. Attach a camera, parachute, and GPS to a weather balloon. Send it soaring into space and then go pick up the pieces!
This particular tutorial comes from YouTube channel Dechert 360, but there are hundreds if not thousands of high altitude balloon projects.
While you may need permission to launch, a high altitude photography launch is one of the easiest projects you can work on, and the few specialist parts are inexpensive and easily obtainable.
This space project idea comes directly from YouTube creator Practical Engineering. This mechanical marvel uses an Arduino compatible development board at its heart, and simply points to the location of the International Space Station.
While this project does use a stepper motor and several specialist mounting points, the ISS tracker code on GitHub should be enough to get you started, regardless of your specific hardware configuration.
This impressive telescope breaks down into two pieces for ease of transporting, and is capable of producing impressive images of the moon and nearby planets!
Produced by the Experiment at Home YouTube channel, this video tutorial covers everything you need to know about constructing your own telescope at home.
The Best 3D Printer for Your Budget in 2017 If you’re looking for a 3D printer, we’ve got you covered. We’ve covered the overall best 3D printer, the smallest, the fastest, and the cheapest — and for all budgets, starting at $300! Read More
Ultimate Beginner’s Guide to 3D Printing 3D printing was supposed to be the new “Industrial Revolution.” It hasn’t taken over the world yet, but I’m here to talk you through everything you need to know to get started. Read More
should help you out here.
This impressive project was built by YouTube channel The Thought Emporium. Built using a satellite and a set of 3D printed gears, this project can track satellites over 20,000 miles away—impressive!
While this project does involve manipulation of microwave frequency bands, it’s not as complex as it sounds. Detailed instructions and implementation specifics are outlined in the video above, and with over 120,000 views, there’s sure to be someone else who’s attempted this project.
8 Awesome Kerbal Space Program Mods Have you ever wanted to design your own rockets, launch them into space, and send astronauts to the moon (or beyond)? Now you can with Kerbal Space Program, a unique game and digital toy that… Read More
, then the next logical step is to build a simulator control console.
Powered by a Raspberry Pi, this shiny interface is a remote controller for your virtual spacecraft. Produced by YouTuber Steven Marlowe, this console outputs real time rocket statistics, and features several lights, buttons, and switches. You could easily expand this into a whole flight deck if you wanted to.
This ambitious project comes from crowdfunded enterprise Copenhagen Suborbitals. With a dream of sending an amateur astronaut into space, this project is definitely on the complex side!
It’s possible to start your own space mission, but you’re probably better off donating to this one if you’re that interested. The team at Copenhagen Suborbitals have got a solid handle on the very basics required for their dream, but even so there’s a long road ahead.
If you need any more convincing that this rocket launch will be a success, then take a look at the rocket gallery, where the impressive engineering work on prototype rockets is documented.
Not just a movie prop, but this suit actually works. Or, at least it would do if it ever went into orbit. After dreaming about space as child, Cameron Smith decided to research and build his own, working space suit.
Eventually teaming up with the previously mentioned Copenhagen Suborbitals, Cameron’s suit has been selected to be used as the official suit of the homemade space mission. Not only that, but the suit is something of an open-source design, or it will be once completed.
What better way to contribute to a space program than to work on a space suit?
This outstanding scale model of the Saturn 5 rocket was produced by Steve Eves. Measuring 36 feet tall, and weighing over 1600 lbs, this model holds the world record for the largest amateur rocket ever successfully launched.
While there’s no doubt that this is an incredibly complicated space project, it shows just what’s possible with a bit of creative thinking. The real Saturn 5 is a complex piece of kit, but that’s not to say that a working scale model isn’t without its challenges.
If you’re a beginner to amateur rocket construction, then you may want to start with something a bit smaller, like the Estes Tandem-X, which measures a more manageable 30 inches tall.
As these projects show, space projects can be produced by more than just the NASA scientists. Whether you’re into functional operating equipment, or bedroom sized replicas, there’s nothing stopping you from attempting some of these projects!
In this blog post, we’ll look at using ProxySQL and VIRTUAL columns to solve ORM issues.
There are a lot of web frameworks all around. Programmers and web designers are using them to develop and deploy any website and web application. Just to cite some of the most famous names: Drupal, Ruby on Rails, Symfony, etc.
Web frameworks are very useful tools. But sometimes, as with many human artifacts, they have issues. Any framework has its own queries to manage its internal tables. While there is nothing wrong with that, but it often means these queries are not optimized.
Here is my case with Symfony 2 on MySQL 5.7, and how I solved it.
The sessions table issue
Symfony has a table to manage session data for users on the application. The table is defined as follow:
CREATETABLE`sessions`(
`sess_id`varchar(126)COLLATEutf8_binNOT NULL,
`sess_data`blobNOT NULL,
`sess_time`int(10)unsignedNOT NULL,
`sess_lifetime`mediumint(9)NOT NULL,
PRIMARY KEY(`sess_id`)
)ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_bin
The expiration time of the user session is configurable. The developers decided to configure it to be one month.
Symfony was serving a high traffic website, and very soon that table became very big. After one month, I saw it had more than 14 million rows and was more than 3GB in size.
Developers noticed the web application sometimes stalling for a few seconds. First, I analyzed the slow queries on MySQL and I discovered that sometimes Symfony deletes inactive sessions. It issued the following query, which took several seconds to complete. This query was the cause of the stalls in the application:
Every DELETE query was a full table scan of more than 14 million rows. So, let’s try to improve it.
First workaround
Looking around on the web and discussing it with colleagues, we’ve found some workarounds. But none of them was the definitive solution:
Reduce expiration time in Symfony configuration. Good idea. One month is probably too long for a high traffic website. But we kept the expiration time configured at one month because of an internal business policy. But even one week wouldn’t have solved the full table scan.
Using a different database solution. Redis was proposed as an alternative to MySQL to manage session data. This might be a good solution, but it could involve a long deployment time. We planned a test, but the sysadmins suggested it was not a good solution to have another database system for such a simple task.
Patching Symfony code. It was proposed to rewrite the query directly into the Symfony code. Discarded.
Create indexes. It was proposed to create indexes on sess_time and sess_lifetime columns. The indexes wouldn’t get used because of the arithmetic addition on the where clause. This is the only condition we have on the query.
So, what do we do if everything must remain the same? Same configuration, same environment, same query issued and no indexes added?
Query optimization using a virtual column
I focused on how to optimize the query. Since I was using 5.7, I thought about a generated virtual column. I decided to add a virtual column in the sessions table, defined as sess_time+sess_lifetime (the same as the condition of the query):
Any virtual column can have an index on it. So, I created the index:
mysql>ALTERTABLEsessionsADDINDEX(sess_delete);
Note: I first checked that the INSERT queries were well written in Symfony (with an explicit list of the fields to insert), in make sure this modification wouldn’t cause more issues. Making a schema change on a table that is in use by any framework, where the queries against the table are generally outside of your control, can be a daunting task.
So, let’s EXPLAIN the query rewritten as follows, with the condition directly on the generated indexed column:
The query now can to use the index, and the number of rows selected are the exact number of the session that we have to delete.
So far, so good. But will Symfony execute that query if we don’t want to modify the source code?
Using ProxySQL to rewrite the query
Fortunately, we already had ProxySQL up and running in our environment. We were using it just to manage the master MySQL failover.
One of the very useful features of ProxySQL is the ability to rewrite any query it receives into another one based on rules you can define. You can create queries from very simple rules, like changing the name of a field, to very complex queries that use a chain of rules. It depends on how complex the translation is that you have to do. In our case, we just needed to translate sess_time + sess_lifetime into sess_delete. The rest of the query was the same. We needed to define a very simple rule.
–>‘^DELETE FROM sessions WHERE sess_lifetime + sess_time < (.*)’,
–>0,
–>‘CASELESS’,
–>‘DELETE FROM sessions WHERE sess_delete < \1’,
–>0,
–>1);
The two fields I want to focus on are:
match_pattern: it defines the query to be matched using the regular expression notation. The + symbol must be escaped using because it’s a special character for regular expressions
replace_pattern: it defines how to rewrite the matched query. 1 is the value of the parameter matched by match_pattern into (.*)
Once created, we have to save the rule to disk and put it on runtime to let it run effectively.
Admin>SAVEMYSQLQUERYRULESTODISK;
Admin>LOADMYSQLQUERYRULESTORUNTIME;
After that, the proxy began to filter the query and rewrite it to have a better execution plan using the index on the virtual column.
Note: pay attention when you need to upgrade the framework. If it needs to rebuild the database tables, you will lose the virtual column you’ve created. Just remember to recreate it and check it after the upgrade.
Conclusion
Developers love using web frameworks because they are very powerful in simplifying development and deployment of complex web applications. But for DBAs, sometimes internal queries can cause a bit of a headache because it is not well optimized or because it was not supposed to run in your “huge” database. I solved my case using ProxySQL and VIRTUAL columns with a minimal impact on the architecture of the system we had and avoided any source code patching.
Take this post as a tip in case you face similar issues with your application framework.
Prior to joining Percona as a Senior Consultant, Corrado spent more than 20 years in developing web sites and designing and administering MySQL. He is a MySQL enthusiast since version 3.23 and his skills are focused on performances and architectural design. He’s also a trainer and a MongoDB consultant.
Every gun owner should own at least one .22lr firearm. The ammo is ubiquitous, and I don’t know of any other cartridge that you can regularly get for $.05/round.
.22 Long Rifle can be used for hunting, target shooting, practice, plinking, and even defending yourself in a pinch. There are even competitions you can enter with rimfire firearms like the .22lr that can be loads of fun.
There are few things more fun than ripping holes in a target with a .22LR handgun.
Now, we’ve talked about the best .22lr RIFLES before, and I’ve talked about my competition Browning Buckmark before, but we’ve never gone over the best .22lr handguns, other than the occasional mention of things like the awesome NAA revolvers for pocket carry options.
Today, that changes.
I want to go over the best .22lr handguns to own for more than just the purposes of pocket carry. These guns are perfect for everything from last-ditch survival options to fun range toys.
For the impatient among you, here are my top picks:
They’re also great first guns for kids, and wonderful training tools. And unlike kids, they’re incredibly cheap to feed, with 5000+ round cases regularly coming in under $300 if you catch them on sale.
So, let’s go over how I chose these particular guns, and why they stand out (and why you should own at least one of them).
Choosing a 22LR Handgun
For me, there’s a few things I’m looking for in a .22LR handgun.
First, accuracy. The humble .22LR is a surprisingly accurate little round at close ranges, so it’s worth getting a gun that can hit what you aim it at. You’ll have a lot more fun hitting those cans setup on a hill than you will watching shots land juuuuust a hair away from them.
Next, shootability and ergonomics. I want something that I’m going to enjoy shooting, not something that’s difficult and forces you to be accurate in spite of it. This is one of my problems with the NAA mini-revolvers.
Pictured: Neat and convenient, not easy to shoot.
Sure, they’re also surprisingly accurate, but anyone who tells you they’re easy to shoot is lying to you, or has never experienced the wonder of a full-size firearm firing .22LR.
Finally, availability and aftermarket support. There’s nothing worse than a $200 gun with $50 mags. I want something that has a lot of support and options available.
As far as aftermarket support, rimfire handguns and rifles (particularly the Ruger 10/22) have a ridiculous number of aftermarket manufacturers making improved triggers, stocks, conversion kits, sights, extractors, magazines, mag releases…the list goes on and on.
And with the low cost of entry (usually sub-$400) to a rimfire firearm, you can experiment a little more and really go all out on the upgrades and accessories, without much worry that you’re going to ruin something expensive.
I highly recommend either the SW-22 Victory, Browning Buckmark, or Ruger 10/22 if you’re looking to start doing any kind of gunsmithing as they’re great platforms to learn on, and you can get really creative with the stuff you can build these guns into.
The Best .22LR Handguns
Alright, here are the guns I’d suggest looking at if you’re trying to decide on a .22LR handgun.
Some of these guns will work for a CCW, in particular the ATI, Beretta, and Walther options make good little guns for folks with low hand strength or for those who are very recoil sensitive, but that’s not why I chose them.
Also, I know there’s roughly a billion other options out there and I can already hear the comments like “what about this Bersa” and “what about that NAA” etc, etc. Now, I don’t want to discourage those comments (quite the opposite) but I can only make this list so long, and I have to start drawing lines somewhere.
So, if I’ve missed an option you think is really good, or there’s something not on the list that you want to know about, be sure to drop a comment below and we can talk about it. Maybe the gun you remembered and I forgot will be exactly what someone else needed.
Alright, I’ve run my mouth long enough, let’s look at some guns.
Ruger Mark IV
Ruger Mark IV
There are a number of excellent .22LR pistols with designs that harken back to the iconic Luger shape (of 9mm Luger fame).
This design is as robust as it is prolific, and has a long development history that began almost a decade before John Moses Browning’s masterwork, the 1911.
The Ruger Mark IV is perhaps one of the finest examples of this design, managing to capture the classic lines, while updating the older toggle-lock design to a simple, but modern blowback design.
It is a 10+1 capacity, magazine fed gun that is a pleasure to hold and shoot, and the heavy bull barrel makes recoil management a cinch. If you’re used to shooting centerfire cartridges of any size, this gun is going to feel like an absolute pushover by comparison.
Long plagued by complaints from owners that the Ruger Mark X series was a pain to take down, the new Mark IV solves that problem effortlessly.
In previous models, reinstalling the frame was relatively easy, but then you had to try and finagle the bolt-stop pin back in, and it was a nightmare fit to make a grown man weep in frustration.
Now, press a button on the rear of the slide, and the gun opens up almost like an AR-15, ready to be cleaned, lubed, and reassembled without fuss.
Like the other two Luger-centric pistols on this list, the Mark IV is as accurate as the ammo and your skill will allow, so don’t try blaming the gun for your misses. Fortunatley, as with any .22LR, practice is cheap, and so is good ammo (relatively speaking) so no excuses.
SW-22 Victory
The SW-22 Victory is the newest of the three Luger-inspired guns on this list, and S&W have approached the design with their typical eye on quality of materials and design.
Of the three, I’d call it the most reliable, even if only by a little bit, especially with mixed ammo. I was shooting ammo that came from a ziplock bag, several different bullet types and manufacturers present, and I had not the first issue with the Victory.
Smith & Wesson SW22 Victory
Like the Mark IV, it’s a 10+1 capacity, mag-fed firearm with a bull barrel, typically a 5.5 inch one, but there are a host of options available from Smith and others.
Where it falls short of the other Luger-style guns here is in aftermarket support (just barely) and accuracy, although it’s certainly a close thing and it could very well just have been me having an off day as I only tested it during one range trip following what I will charitably call a late night.
Fortunately for the SW-22, it also has one of the lower MSRPs of any of the Lugeresque options here, so if you’re looking for something that’ll get the job done without breaking the bank, this is certainly a strong contender.
The one other thing I’ll note is that Smith and Wesson took a beating for a while on their M&P triggers in their handguns (something that has been rectified in the 2.0 series). The triggers were not good, certainly not by comparison to S&W’s other triggers, particularly in their revolvers.
The SW-22, despite coming out around the same time as the older generation M&Ps, was not cursed with such an affliction.
The trigger on this thing is damn good, and while aftermarket options and some carefully applied gunsmithing knowledge can certainly make it better, it’s perfectly adequate for most folks out of the box.
SW22 taken down.
Browning Buckmark
Next, we have the final Luger-style gun on the list, and my personal favorite, the Browning Buckmark.
The Buckmark is mostly my favorite because it was one of the first guns I purchased for myself, many years ago, but there are other, more objective reasons as well.
First, it has the nicest trigger of the three out of the box, which for me was big benefit. I really enjoy a nice, crisp trigger that makes accuracy easy, and the Buckmark certainly has that.
It also has a ton of factory options available, which makes it easy to find the Buckmark that best suits your needs.
The one area that really drags it down is, well, taking it down.
To clean the other two Luger knockoffs, you have either a button to push or a pin to rotate, and that’s pretty much it. Baddabing, baddaboom, you’re done.
The Buckmark requires you to remove the slide bridge which is annoying enough by itself but it also means you need tools, yes tools, plural, to take the thing down.
Tandemkross Everything Kit on Buckmark
Yes, it’s just two allen wrenches, and no, it’s not particularly difficult, but it is needlessly complicated, and it leaves me feeling guilty every time I take it to the range because I know all that dirty rimfire shooting I just did is going to make my gun a pain in the ass to clean.
Of course, the Buckmark also excels in other areas, and like just about every mag-fed gun on this list, comes in a 10+1 capacity, and like the Mark IV and the victory, it also comes with a 5.5 inch bull barrel. For aftermarket accessories, I’d have to again recommend Tandemkross, just like I would for the Ruger and the Smith above.
Reliability wise, I’d put it above the Mark IV and below the Victory, and looks-wise, I’d put it at the top of the heap, but you may think differently. That’s fine, this is America and you’re absolutely free to be wrong.
Walther P22 QD
The legendary Walther P22 was noted for it’s awesome trigger, clean design, and tactical styling.
All in all, it was an excellent little gun save one thing: it only worked when it felt like it, and overly-tight tolerances meant you got maybe one mag of reliable function out of it before it needed to be cleaned again.
Come on, don’t lie. That thing looks sexy as all hell.
The new QD model solves this issue, and updates the classic design while keeping the amazingly nice trigger that blows most other factory pistol triggers out of the water.
Best of all, the P22 is a DA/SA pistol so you have that second-strike capability if you have a light primer strike, which is a common issue with .22LR ammo.
In DA mode, you’ll be dealing with a stiff but smooth 11lb trigger pull, and with the hammer back you’ll get an incredibly crips break right at 4lbs of pressure.
Honestly, this is the gun I’d have if I could only own one from this list. It has a 10+1 capacity just the like the other mag-fed options here, and while it doesn’t have a lot of aftermarket support, it doesn’t need a whole lot.
If you’re going to carry an easy-to-shoot .22, this is the way to go as well as it is one of the more reliable options, while being a reasonable size to carry, unlike the 34-38oz behemoths we’ve covered so far.
The slide serrations also make it easy for those with low hand strength to rack in a round, and the sights, while kind of a cheap polymer, are more than accurate enough for self-defense distances.
That being said, the gun is great fun to shoot at the range, and its quite the looker. Walther certainly didn’t skimp in the design department on this thing.
Like most of their guns, there’s a little bit of the James Bond about it, and I really like that. Plus, it’s usually found under $250 and I’d call anyone charging much more than that a ripoff, so there’s really no reason not to have one.
Heritage Rough Rider .22
If you’re looking for something a little more classic, but just as fun, the Heritage Rough Rider is a strong contender. A single-action six shot like those wielded by your favorite Western heroes, the Rough Rider might just have the best fun-to-money ratio of any gun on the list.
The single action and loading-gate design means you have to pull back (or fan) the hammer for each shot and load and unload each round individually. No speed loaders, no slapping an ejection rod to spit all six spent shells to the ground at once.
All in all, it’s a very slow-paced, almost zen experience to shoot one, and you can really stretch a box of ammo for several afternoons at the range.
Heritage Rough Rider Revolver
It’s also a great gun for working on your accuracy as the low round count and almost-but-not-quite painfully slow reload will have you picking and placing your shots carefully.
The trigger is surprisingly good, no doubt a product of the simple single-action design more than anything, but that’s okay. It’s more than good enough for the gun’s real purpose: having the most fun for the least money.
Yeah, it’ll shoot snakes or discourage predators of the two and four-legged variety, and it’ll certainly make a good training tool for youngins and new shooters, but fun is what this gun is all about.
And the price certainly helps. You can get fancy commemorative versions, and versions with nice grips, and ones with interchangeable .22 Magnum cylinders, and all that, but the base version, with a .22lr cylinder and a 6.5” barrel will set you back between $100 and $125.
Next, we have one of the most legendary DA/SA revolvers to ever exist, the Ruger GP-100. For a long time, Ruger’s legendarily tough GP-100 was only available in a 6-shot .357 model (which I own and adore), but as of late, I’m seeing more and more .22LR versions on the shelf at my local gun store.
I can’t sing the praises of the GP-100 enough. Its rugged monolithic design means that it’ll almost certainly outlive you, and possibly your children and grandchildren as well if it’s cared for at all.
You could also probably bury it in the dirt somewhere for the sole purpose of having it dug up 200 years from now, and it’d probably still work (and be of great help to the revolution’s fight against our robot overlords circa 2200).
Ruger GP-100
The .22LR version is a ten shot model available with a 4” and 6” barrel, and its just about as accurate as you could want, something that’s in no small part due to the better-than-average trigger and factory fiber optic front sight post.
It is one of the pricier guns on this list with a typical going price of about $650, which sounds like a lot if you don’t realize you’re getting one of the best, if not the best, .22LR revolver around.
That about does it for this one. These .22LRs are sure to make you smile, and are great for everything from defense to hunting to plinking and target shooting. I own, or have owned all of these save the Victory, and I regret selling the ones I don’t have anymore.
This should about cover any use you should have for a .22LR handgun, but if you’re looking for something specific, or wanting to pick my or your fellow commenter’s brains about any of these guns, or even one that’s not on the list, be sure to drop a comment below!