Archive for the ‘Java’ Category

Exciting upcoming MySQL events

Январь 24th, 2012

At the IOUC leaders’ summit in San Francisco this week, key leaders from Oracle, Java and MySQL user groups world wide have been meeting. This has included the key Oracle MySQL resources from the community, marketing and product teams. The Java User Groups and MySQL User Groups have been well represented and there has been very welcoming discussion with the IOUC about how we can become active within the Oracle Community.

There has been key discussions of upcoming and proposed MySQL events including the great outreach by the Oracle MySQL team with existing Open Source conferences this year including Scale, FOSDEM and South East Linuxfest just to name a few.

You can see the upcoming events at http://mysql.com/news-and-events/events/. In February alone there will be events in North Carolina, California, Texas, Frankfurt Germany and Stockholm Sweden. I will also be speaking in Denver at 2 events and Salt Lake City.

There is a much longer list then what is shown here, and we are working on getting the full list more available.

More info by Dave Stokes at SCaLE’s MySQL Day a big hit and Keith Larson More User Groups.


PlanetMySQL Voting: Vote UP / Vote DOWN

Connector/J extension points – exception interceptors

Ноябрь 22nd, 2011

A third built-in extension point for MySQL Connector/J is the ExceptionInterceptor interface.  This is the third extension point covered in my recent JavaOne and Silicon Valley Code Camp presentations, and is very useful for diagnosing specific Exceptions encountered without modifying application-side code. This corresponds to slide #60 in my slide deck, and there are two Java files we’ll reference from my demo code:

  • demo.connectorj.ExceptionInterceptorExample
  • demo.connectork.plugins.ExampleExceptionInterceptor

To implement an exception interceptor, you need to do the following:

  1. Create a Java class which implements com.mysql.jdbc.ExceptionInterceptor
  2. Configure Connector/J to use your exception interceptor by passing the fully-qualified class name as the value for the “exceptionInterceptors” property.

Like statement interceptors, this extension point is stackable – you can create multiple exception interceptors, passing them in as a comma-delimited list of fully-qualified class names.  The exception interceptors are executed in order in which they are defined in the connection property.

The demo here simply demonstrates how this work, but doesn’t give much of an idea of the power behind this interface.  The demo code executes a command that’s not valid SQL syntax – which will trigger a server-side error – catches the normal exception, wraps it with some additional text in the message before returning it to the application (where it is hopefully logged).  So what can you do with this?

There are certain errors where diagnosis requires additional information about either connection or server state – at the time the exception is raised.  This gives you a hook to enable collection of this data.  For example, certain NDB (Cluster) errors map to the same MySQL Server error code and message, and you can get more information from the NDB problems by issuing SHOW WARNINGS immediately after the error.  Unless you want to recode your application, there’s a lot of value in the ability to add an ExceptionInterceptor which looks for such errors, executes the SHOW WARNINGS, takes the details returned and shoves them into the Exception message text.

Another example might be when you get a server error that indicates the connection character set is set to something other what it should be set to, based on the configuration settings, and you want to know what session character set or collation is in use.  Unless you change your application code, you can only assume what it should be – unless you implement an ExceptionInterceptor that collects that data when the problem is encountered and logs that information for you.

Generally speaking, this is an extension point that you probably won’t leverage for normal operations, but can be very useful for diagnosing Exceptions that are difficult to reproduce outside the context of your Java application deployment.  Because ExceptionInterceptors are only called when handling a SQLException thrown from Connector/J code, you don’t have to worry too much about performance penalties in production deployments.

 


PlanetMySQL Voting: Vote UP / Vote DOWN

Connector/J extension points – statement interceptors

Октябрь 18th, 2011

Continuing the review of MySQL Connector/J’s built-in extension points from my recent JavaOne and Silicon Valley Code Camp presentations, this blog posting will focus on the StatementInterceptor extension point.  As the name suggests, this allows you to hook into statement execution and alter behavior – without changing application-side code.  This corresponds to slide #59 in my slide deck, and there are two Java files we’ll reference:

  • demo.connectorj.StatementInterceptorExample
  • demo.connectork.plugins.ExampleStatementInterceptor

To implement a statement interceptor, you need to do the following:

  1. Create a Java class which implements com.mysql.jdbc.StatementInterceptorV2
  2. Configure Connector/J to use your statement interceptor by passing the fully-qualified class name as the value for the “statementInterceptors” property.

This extension point is stackable – you can create multiple statement interceptors, passing them in as a comma-delimited list of fully-qualified class names.

The example provided in the demo code is pretty bland, but illustrates what can be done.  In the demo code, we’ve implemented the preProcess() method to check for a certain trigger (“/* test */” in this case), which triggers entirely different behavior than what would normally transpire.  This code simply returns the result of  “SELECT NOW()” when triggered, instead of whatever would normally be executed on the server.  You’ll probably never need this particularly functionality, but there’s other interesting stuff you could do:

  • Add memcached without changing a line of application code, by checking memcached before executing a query, and caching the results after retrieving non-cached data from MySQL.
  • Work around MySQL server problem areas without changing application code.  Maybe you have slow-performing subqueries in an application you cannot change?  Use statement interceptors to rewrite them to more better-performing JOIN syntax equivalents.
  • Perform some standard result set transformation by wrapping ResultSetInternalMethods returned object.
  • Add fine-grained conditional audit logging or access control without changing application code.
  • Track down problematic statements that you suspect may be issued by the application, but not logged anywhere else.
  • Shard your data, and use statement interceptors to route statements to appropriate MySQL instances (or combine results fetched from multiple MySQL servers)  – again without changing application code.
  • Implement low-overhead “ping” operation for connection pools that don’t allow you to define your own validation query.

There’s a lot that can be done with statement interceptors, and they are very easy to wire up – there’s really only five methods you need to implement:

  • init()  – You can set up state variables here, if needed.  Returns void, so leaving this empty is fine.
  • preProcess() – This is where you return a ResultSetInternalMethods object if you want to bypass the normal operation of the statement.  This is called before the statement is sent to the server, so you can change what is sent – or even bypass the sending – here.  If you return null, the driver executes the statement as it normally would.  If you return a non-null object, further execution is bypassed.  Note that the SQL String argument will be null for PreparedStatement objects; you’ll need to handle Statement and PreparedStatement executions differently in order to examine the SQL being sent.
  • postProcess() – Like preProcess(), but invoked by the driver after the server has returned a result set.  This allows you to change the results returned or wrap them with some sort of custom decorator.
  • executeTopLevelOnly() – Return true if you are issuing queries inside preProcess() or postProcess() that could cause infinite recursion.
  • destroy() – Clean up any local references you created in init() here.

The demo code provided will give you a simple example of how to implement statement interceptors, but what you do with them is really limited only by your imagination.

 


PlanetMySQL Voting: Vote UP / Vote DOWN

451 CAOS Links 2011.08.31

Август 31st, 2011

MapR and Funambol raise funding. VMware virtually supports PostgreSQL. And more.

# MapR raised $20m series B for its Hadoop distribution from Redpoint Ventures, Lightspeed Venture Partners and NEA.

# Funambol raised $3m in funding from previous investors HIG Ventures, Pacven Walden Ventures and Nexit Infocom.

# VMware launched vFabric Postgres as part of vFabric Data Director database-as-a-service launch.

# Citrix released a new edition of CloudStack, making the whole cloud management product available using the GNU GPLv3.

# Yahoo has contributed 84% of Apache Hadoop lines of code and 72% of patches, according to Hortonworks’ analysis.

# Red Hat invited Red Hat Enterprise Linux users to help discuss features for Red Hat Enterprise Linux 7.

# Talend announced that Peter Gyenes has joined its Board of Directors.

# Mandriva announced the release of Mandriva 2011.

# The Document Foundation announced the release of version LibreOffice 3.4.3, intended for enterprise deployments.

# Zmanda announced the availability of Zmanda Cloud Backup (ZCB) 4.0.

# The 10th Circuit Court of Appeals ruled against on SCO’s appeal that it, and not Novell, owned the Unix copyrights.

# Oracle retired its licence for distributing its Java with Linux.

# Bruce Byfield wrote an interesting article on how Linus Torvalds and other open source developers avoid burnout.


PlanetMySQL Voting: Vote UP / Vote DOWN

Creating JDBC Connections Doesn’t Have To Be Slow (or "not the reason to be using a pool")

Август 24th, 2011

Hanging out in #mysql on freenode the other day, I overheard someone saying that the reason to use connection pools with MySQL is because JDBC connections are expensive to create. That is true out of the box, but mostly because the out of the box behavior of MySQL's JDBC driver is to be standards-compliant. If you know that your DBA and your developers aren't doing crazy things with the database (changing configurations without letting the developers know, going around the "standard" API calls to start/end transactions, etc), then you can get to the point where connection setup is no slower than any other API. Does this mean you shouldn't use a connection pool? NO! (more on this next week).

Here's an iterative overview of the changes made in configuration, and how they affect what queries the driver does on initialization.

First, asking the driver to connect with default configuration results in the following statements being issued for every connection:

SHOW VARIABLES WHERE Variable_name ='language' OR Variable_name = 'net_write_timeout' 
  OR Variable_name = 'interactive_timeout' 
  OR Variable_name = 'wait_timeout' 
  OR Variable_name = 'character_set_client' 
  OR Variable_name = 'character_set_connection' 
  OR Variable_name = 'character_set' 
  OR Variable_name = 'character_set_server' 
  OR Variable_name = 'tx_isolation' 
  OR Variable_name = 'transaction_isolation' 
  OR Variable_name = 'character_set_results' 
  OR Variable_name = 'timezone' 
  OR Variable_name = 'time_zone' 
  OR Variable_name = 'system_time_zone' 
  OR Variable_name = 'lower_case_table_names' 
  OR Variable_name = 'max_allowed_packet' 
  OR Variable_name = 'net_buffer_length' 
  OR Variable_name = 'sql_mode'
  OR Variable_name = 'query_cache_type' 
  OR Variable_name = 'query_cache_size' 
  OR Variable_name = 'init_connect'

SELECT @@session.auto_increment_increment
SHOW COLLATION
SET NAMES utf8
SET character_set_results = NULL
SET autocommit=1
SET sql_mode='STRICT_TRANS_TABLES'

WIth this out of the box configuration, my development rig is topping out around 115 connections/second.

Now, let's tell the driver that we're not going to change any of those variables above while the application is deployed, so that it may cache them by adding "cacheServerConfiguration=true" to the connection string. The first connection will take the same amount of time, but subsequent connections using the same URL in the same JVM will not issue the "SHOW VARIABLES..." statement. We now end up with the following SQL statements on all connections after the first one:

SET NAMES utf8
SET character_set_results = NULL
SET autocommit=1
SET sql_mode='STRICT_TRANS_TABLES'

Next, let's make sure that we've set 'character_set_client' and 'character_set_server' on mysql to match what we're requesting, which for this test was UTF8. Once that is done, the driver no longer has to issue "SET NAMES utf8":

SET character_set_results = NULL
SET autocommit=1
SET sql_mode='STRICT_TRANS_TABLES'

We can get rid of the "SET character_set_results = NULL" if we set the server to match what the JDBC driver is requesting. The default (NULL), is so that character set conversions on result sets is pushed out to the clients, rather than burning CPU at the mysql server, since Java can convert between all character sets MySQL supports on its own. In this example, we assume that the database data is always in UTF-8, so setting by setting 'character_set_results' in MySQL to "utf8", and adding "characterSetResults=UTF-8" to the connection string, we're now at:

SET autocommit=1
SET sql_mode='STRICT_TRANS_TABLES'

I generally prefer all applications to be using a transactional storage engine like InnoDB, and strict mode to keep the data clean and consistent and catch programmer errors, so by adding "sql_mode=STRICT_TRANS_TABLES" to the server's my.cnf, the JDBC driver only issues these statements on connect:

SET autocommit=1

Java developers shouldn't be doing end-runs around Connection.commit(), Connection.rollback() and Connection.setAutoCommit(boolean) by issuing those as regular statements, so in almost all cases it's then safe to add "useLocalSessionState=true" to the connection string, and you end up with zero statements issued by the JDBC driver for connection setup after the first to grab the server configuration to be cached.

After those few small tweaks to the connection string, we're now able to create and close 667 connections/second from a single thread on my old beater of a Macbook Pro to a MySQL server on the same box (this value might be somewhat lower if the connection actually has to go over the wire). For comparison, PHP-5.3.6 using mysqlnd and the following script can create and close 500 connections/second on the same machine:

<?php
date_default_timezone_set("America/Chicago");

$now = new DateTime;

for ($i = 0; $i < 10000; $i++) {
 $link = mysql_connect('127.0.0.1', 'someUser', 'somePassword');
 if (!$link) {
        die('Could not connect: ' . mysql_error());
 }
 mysql_close($link);
}

$then = new DateTime;
$elapsed = $then->diff($now);

echo $elapsed->format('%s seconds');

?>
Stay tuned next week, when we see why you still might want to use a connection pool, even though you can create connections more than fast enough :) Want to know where to read up on all of these configuration parameters? Check out our fine manual at http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html
PlanetMySQL Voting: Vote UP / Vote DOWN

451 CAOS Links 2011.08.12

Август 12th, 2011

Couchbase raises $14m. AppFog raises $8m. Much ado about Percona Live MySQL Conference and Expo. And more.

# Couchbase raised $14m in series C funding for its NoSQL database.

# AppFog raised $8m series B funding for its PHP-based platform-as-a-service.

# Percona announced its plans to host a Percona Live MySQL Conference and Expo on April 10-12, effectively replacing the O’Reilly MySQL Conference and Expo.

# The announcement sparked some rumblings of discomfort around the MySQL community with Giuseppe Maxia and Sheeri Cabral disputing Baron Schwartz’s claim that “to the best of our knowledge, no one else was planning one” and Monty Widenius stating that he had “personally talked with Percona about this a few weeks ago”.

# SkySQL’s Kaj Arno also called for the community to rally around an event focused on users, while Henrik Ingo welcomed the Percona event and doubted whether plans for a vendor-neutral event had got very far. Roland Bouman also voiced his support for the event.

# Red Hat announced that its Red Hat OpenShift Platform-as-a-Service now supports Java Enterprise Edition 6

# Jaspersoft announced Self-Service Express, offering open source users BI documentation and knowledge base articles.

# Microsoft apparently no longer thinks Linux is a competitive threat to its desktop business.

# Cisco and Twitter joined the Open Invention Network.

# Fabrizio Capobianco asked if there really is room for a third mobile OS.

# Alembic 1.0, the open source computer graphics interchange format jointly developed by Sony Pictures Imageworks and Lucasfilm was released.


PlanetMySQL Voting: Vote UP / Vote DOWN

On Password Strength

Август 11th, 2011

XKCD (as usual) makes a very good point – this time about password strength, and I reckon it’s something app developers need to consider urgently. Geeks can debate the exact amount of entropy, but that’s not really the issue: insisting on mixed upper/lower and/or non-alpha and/or numerical components to a user password does not really improve security, and definitely makes life more difficult for users.

So basically, the functions that do a “is this a strong password” should seriously reconsider their approach, particularly if they’re used to have the app decide whether to accept the password as “good enough” at all.


PlanetMySQL Voting: Vote UP / Vote DOWN

MariaDB now available as a hosted database via Jelastic cloud platform

Август 8th, 2011

About Jelastic:

Jelastic is the next generation of Java Platforms as a Service.

Unlike previous cloud platforms, Jelastic:

  • Can run any Java application and so does not require developers to change their code or get locked-into the platform,
  • Can scale any application up and down by automatically adding or removing memory and CPU units depending on the application load,
  • Takes all configuration and management worries away: developers simply specify the application stack and database options they need and Jelastic creates, configures, and maintains the environment for them
  • Supports a wide range of application server stacks including Tomcat, JBoss, Jetty, and GlassFish
  • Out of the box, allows users to get a preconfigured instance of MariaDB up and running and available to the application.

A beta version of Jelastic is available at http://jelastic.com and it is free throughout the beta program including the use of MariaDB.

You can see videos, read more, and deploy your Java applications in Jelastic today at http://jelastic.com.

Supporting quotes:

Monty Widenius – founder of MySQL and creator of MariaDB:

“It is now even easier to get started with MariaDB. Jelastic lets any Java developer simply upload a Java WAR package, pick MariaDB in the Jelastic environment configuration, and get the best database out there up and running. Java has just received its next generation of Platform-as-a-Service system and it is great that MariaDB is a part of it.”

Hivext CEO Ruslan Synytskyy:

“We are excited to have MariaDB available as a storage option in Jelastic. Full compatibility with MySQL and much improved perfomance, scalability, and feature-set give our customers a state-of-the-art database to suit their application needs.”

About MariaDB:

MariaDB strives to be the logical choice for database professionals looking for a robust, scalable, and reliable RDBMS (Relational Database Management System). MariaDB can be deployed as a drop-in replacement for the popular MySQL database and it is built by some of the original authors of MySQL with assistance from the broader community of Free and open source software developers. In addition to the core functionality of MySQL, MariaDB offers a rich set of feature enhancements including alternate storage engines, server optimizations, and security and performance patches. More information on MariaDB is available at http://mariadb.org and http://kb.askmonty.org.

About Hivext Technologies:

Hivext Technologies is the creator of Jelastic – Java platform as a service which runs a vast variety of Java application stacks, SQL and NoSQL
databases, and can automatically vertically scale up and down any Java application. Jelastic is available as a service for Java developers at
http://jelastic.com, and as a package for hosting providers wishing to add Java hosting to their portfolio. Learn more at http://jelastic.com.


PlanetMySQL Voting: Vote UP / Vote DOWN

Developer Week in Review: Lion drops pre-installed MySQL

Август 3rd, 2011


A busy week at Casa Turner, as the infamous Home Renovations of Doom wrap up, I finish the final chapters of "Developing Enterprise iOS Applications" (buy a copy for all your friends, it's a real page turner!), pack for two weeks of vacation with the family in California (Palm Springs in August, 120 degrees, woohoo!), and celebrate both a birthday and an anniversary.



But never fear, WIR fans, I'll continue to supply the news, even as my MacBook melts in the sun and the buzzards start to circle overhead.

The law of unintended consequences

Lion ServerIf you decide to install Lion Server, you may notice something missing from the included software: MySQL. Previous releases of OS X server offered pre-installed MySQL command line and GUI tools, but they are AWOL from Lion. Instead, the geek-loved but less widely used Postgres database is installed.

It seems pretty obvious to the casual observer why Apple would make this move. With Oracle suing Google over Java, and Oracle's open source philosophy in doubt, I know I wouldn't want to stake my bottom line on an Oracle package bundled with my premiere operating system. Apple could have used one of the non-Oracle forks of MySQL, but it appears they decided to skirt the issue entirely by going with Postgres, which has a clear history of non-litigiousness.

Meanwhile, Oracle had better be asking themselves if they can afford to play the games they've been playing without alienating their market base.

South Korea fines Apple 3 million won, which works out to ...

Apple has bee been hit with a penalty from the South Korean government that's a result of the iPhone location-tracking story that broke earlier this year. Now, Apple may have more money than the U.S. Treasury sitting in petty cash right now, but it will be difficult for them to recover from such a significant hit to their bottom line: a whopping 3 million won, which works out to a staggering ... um ... $2,830. Never mind.

Strata Conference New York 2011, being held Sept. 22-23, covers the latest and best tools and technologies for data science -- from gathering, cleaning, analyzing, and storing data to communicating data intelligence effectively.

Save 20% on registration with the code STN11RAD

Java 7 and the risks of X.0 software

Java 7 was recently released to the world with great fanfare and todo. This week, we got a reminder why using an X.0 version of software is a risky endeavor. It turns out that the optimized compiler is really a pessimized compiler, and that programs compiled with it stand a chance of crashing. Even better, there's a chance they'll just go off and do the wrong thing.

Java 7 seems to be breaking new ground in non-deterministic programming, which will be very helpful for physics researchers working with the Heisenberg uncertainty principle. What could be more appropriate for simulating the random behavior of particles than a randomly behaving compiler?

Got news?

Please send tips and leads here.

Related:


PlanetMySQL Voting: Vote UP / Vote DOWN

CAOS Theory Podcast 2010.12.10

Декабрь 11th, 2010

Topics for this podcast:

*Oracle, Java, the Apache Software Foundation and open source
*An update on some open source database and data management players
*CorraTech grows with support for open source application alternatives
*Red Hat-Makara acquisition analysis and impact
*Linux kernel report shows strong support, but what now for Novell?

iTunes or direct download (29:31, 5.1MB)


PlanetMySQL Voting: Vote UP / Vote DOWN