Blog

Blesta 3.0: Efficiency

May 18, 2012 | Posted by Cody


As lead developer, my primary focus has been on designing an efficient system. Since our primary data store (where we make the most reads/writes) is the database, naturally this is where the smallest change can have the biggest impact. I’ve already discussed a number of changes we’ve made to the database system including switching to InnoDB and the use of PDO. The last is the use of unbuffered queries.

Buffered Queries

Buffered queries fetch (e.g. buffer) all records into memory from the database server and automatically close the cursor, allowing other queries to be executed. You might take this for granted. For example, you may have something like:

<?php
// What looks like 'nested' queries...
$statment = mysql_query($sql);
while ($data = mysql_fetch_assoc($statment)) {
    $statment2 = mysql_query($sql2);
    while ($data2 = mysql_fetch_assoc($statment2)) {
        ...
    }
}

This might be all fine and dandy, but assume that the first query finds 1,000,000 rows. If each row contained just 1 KB of data, that’s 976 MB of memory consumed! Keep in mind that the memory is consumed at mysql_query(), so it doesn’t matter how many rows you actually fetch (using mysql_fetch_*). Moreover, the memory isn’t freed until the program terminates or you explicitly invoke mysql_free_result().

Unbuffered Queries

Unbuffered queries, on the other hand, are not buffered into memory. Each row remains on the database server until fetched. This can drastically reduce memory consumption on the web server.

The only downside is that you can’t create what look like “nested” queries (as in my example above). But that really isn’t a downside at all, because it forces you to look at better methods for fetching or querying data. Like limiting your result set and fetching all results.

The Record component in Blesta, in conjunction with PDO, make unbuffered query support almost seamless. You really only need to be concerned about closing the cursorif you’re explicitly working with PDOStatement objects.

<?php
// Manually work with the statement...
$users = array();
$user_stmt = $this->Record->select()->from("users")->getStatement();
foreach ($user_stmt as $user) {
    $users[] = $user;
}
$user_stmt->closeCursor();
 
// Or just let the Record component to handle it all...
$users = $this->Record->select()->from("users")->fetchAll();

While the benefit of unbuffered queries may not be entirely evident on small data sets, there’s no doubting it improves efficiency. And that’s what creating an enterprise-level application is all about.

Blesta 3.0: Currencies (video)

May 4, 2012 | Posted by Paul


I came into work this morning with literally no idea what the video was going to be about today. I have a list of topics, but nothing felt right and then I realized we haven’t really talked about currencies much. It’s part of a larger topic, Internationalization, and with what we’re doing with language support and the translator it only makes sense that we should discuss currencies.

Of course, a big part of currencies is multi-currency support and v2.5 has it, but it’s much improved in v3. In v2.5, multi-currency has to be explicitly enabled and everything revolves around the default currency. While v2.5 can accept payments in many currencies, clients are billed based on the exchange rate to the default currency. So, the biggest difference between v2.5 and v3 is that prices can be specified at the package level for each individual currency, effectively fixing prices. Only when a price is not available for the currency does the exchange rate come into play.

  1. Prices can be set for each currency at the package level, which overrides the exchange rate.
  2. Multi-currency doesn’t need to be enabled, just use it if you want to use it.
  3. Exchange rates can be fetched from Foxrate, Yahoo Finance, or Google Finance.
  4. Exchange rate updates can be disabled and exchange rates manually updated.
  5. New package period options Day, Week, and Year in addition to Monthly and One Time.
  6. Cancellation fees can be assessed and configured at the package level.

Interesting fact! With Day, Week, Month, and Year package period options now available, terms can range between 1 and 65535 (216 – 1) which equates to 65535 * 4 + 1, or 262,141 possible service terms available. So much for just monthly, quarterly, semi-annual, and annual huh? Do your own thing.

The video is below, as usual you can make the video full screen, and be sure to turn on your sound.

Blesta 3.0: The Translator (Update)

April 27, 2012 | Posted by Paul


In January we announced the availability of a language crowdsourcing project, the Blesta Translator. The goal of the project is to facilitate the translation of Blesta into many languages, and to ship these languages with Blesta, starting with version 3.

This week we made a few additional changes live, and they are –

  1. Added Nederlands, NL (nl_nl) to the list of available languages
  2. Added a machine translation (Google) for reference
  3. Added “In Order” and “For Confirmation” translation methods
  4. Added some context to language strings including terms, filename, and type

#2 Machine Translation

The machine translation is available for all translation methods, “Random”, “In Order”, and “For Confirmation”. By default it is not displayed, but will be shown when a link is clicked. The idea is that it may be useful to see the Google translation, but that it shouldn’t be relied on, or copied without forethought.

#3 Additional Translation Methods

The goal of the translator isn’t simply to get translations, but to get good translations.

When different people translate a term identically, it has a higher weight than terms that are only translated by one person. Such terms become “confirmed”, and are trusted to be more accurate. So, the “For Confirmation” translation method displays the best possible translations by other people. One of these translations can be accepted by clicking on it. Alternatively a different translation may be entered like normal.

The “In Order” translation method is pretty self-explanatory, terms are given in alphabetical order with the goal of completing a translation. This means that some terms may be skipped initially until the translation is completed as a whole. Once the translation is completed, terms that were intentionally skipped will be presented.

The end goal is to make several translations available. A version translated wholly by a specific person, a confirmed only translation that may be missing some terms (missing terms are shown in the default language), or a complete translation consisting of confirmed only or both confirmed and unconfirmed terms. The latter are the ones we will include with Blesta by default, but all will be available for direct download in the future.

Thanks for reading! If you know another language, please sign-up and contribute

Video next week? Probably.

Blesta 3.0: Automation

April 13, 2012 | Posted by Paul


Part of my job in the development of v3 is to take a step back and consider how each and every feature in Blesta can be improved over previous versions. Lots of thought, and many discussions surround even the simplest details of both the external and internal workings of Blesta, the visible and invisible.

Today I want to compare and contrast, and reveal how we handle automation in v3.

v2

Version 2 has a Cron Status & Setup page, under Settings > API/Cron Settings. The intent of this page is to show you when the cron last ran, how to set up your cron, and provide a method by which to run the cron manually. We were the first to secure the cron with a key, preventing it from being run by unauthorized users. Overall very basic, and it works pretty well.

v3

Version 3 does everything mentioned above, but in a simpler, more intuitive way — with the addition of being able to update the cron key right here. This key is now separate from the API key, which it shared in v2.

This is a good replacement for v2, and we could have stopped there.. but like I said in the opening, a lot of thought, many discussions.. and I’ll add, a lot of planning and development time goes into each and every feature.

One thing that bothers me a lot with v2 is that I can’t set exactly when I want a particular task to execute. Some tasks run once daily, some run every x minutes. The daily tasks run every day at midnight, and for the most part, the more frequent ones are at the mercy of how often the cron is scheduled to run.

This creates some issues, first of all is that midnight emails probably don’t have the highest read rate. Secondly, midnight account suspensions for non-payment result in emergency tickets at a time when most of your staff is sleeping or in the shower.

So, the actual cron job should run every 5 minutes, and you should be able to schedule when each task runs. Right? We think so. It’s almost common sense, but nobody has done it until now.

Above is what Invoice Creation and Auto Debit tasks look like. In this case, we have them both set up to run at 2pm daily. These are 2 tasks out of more than a dozen.

What about more frequent tasks?

This option illustrates how paid pending services, such as exist when a new order is placed, are provisioned.. every 5 minutes.

In addition to being able to schedule each task, they can also be explicitly disabled.

Developer Candy: Plugins can register automation tasks.

Another important thing to note is that all the times are in your local timezone — or whatever you set your timezone to be, regardless of the server time. Additionally, all dates and times in Blesta everywhere are stored in the database as and converted from UTC, which means you can change your timezone without affecting the stored value.

The default options will be perfect for most people, and there will be no real necessity to dig in and tweak these around.. Really, it’s not that important, but I wanted to show you for two reasons. 1. It’s a neat, practical feature and more importantly.. 2. It gives you a glimpse into how we work, how detail oriented we are, and how serious we are when it comes to usability.

Hope you have a nice weekend. Speaking of weekends…

Nerd Alert: If you play a game called Minecraft, we’ve got a Minecraft server up and running at 74.80.216.146. Come join us, some of our friends, and some of their friends as we build random stuff. HostMaster = Me, Awesomisitist = Tyson, Codelphious = Cody.

Blesta 3.0: Invoice Customization (video)

April 6, 2012 | Posted by Paul


Cody posted an article last week on Software Licensing, which I found amazing. Be sure to check it out if you haven’t already.

This week I’ve got another video, and it’s all about options available for invoices. There are many improvements in v3 when it comes to invoices, so I thought you might like to see what we’ve got cookin.

  1. Two all newly designed invoice templates available.
  2. Invoice formats are now available. Add a prefix, suffix, and/or the year to invoice numbers.
  3. Set or change the next invoice number anytime.
  4. Have invoice numbers increment 1 at a time or in multiples, ie Invoice # 5, 7, 9.
  5. Pad invoices to a specific length, ie Invoice # 00001, or xxxx1.
  6. Add your logo, a background image, and company name and address to invoices.
  7. US Letter, and A4 paper sizes now supported.
  8. A PAID watermark can now be displayed on paid invoices.

Invoices are flexible yet simple, fully internationalized, clean, and they print beautifully. I’m really happy with the changes we’ve made to invoices since 2.x and I hope you are too!

The video is below, as usual you can make the video full screen, and be sure to turn on your sound.