-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question re: Filters #18
Comments
I should add the following, because I'm starting to see where it may reference in the index's filter column list, which isn't exactly clear when you're using // Open a connection
$index_id = $this->_read->getIndexId(
$this->_database,
$query->get_table(),
$query->get_index(),
$query->get_fields()
);
// Create the select query
$query = $this->_read->selectByIndex(
$index_id,
$query->get_type(),
$query->get_key_values(),
$query->get_limit(),
$query->get_offset(),
$filter_values
); Would I be right in assuming that I need to add the filter column list to the |
thanks for choosing my bike :) for example: $reader = $this->getReader();
$indexId = $reader->getIndexId(
$this->getDatabase(),
$this->getTableName(),
'PRIMARY',
array('key', 'text'),
true,
array(0 => 'num')
); here I opened some table and PRIMARY index with columns (key, text). The next parameter returnOnlyId ('true') need us to get only int of opened index number. And the last array is filter column (num), later we can use it when we will need to use something like where in SQL. $selectQuery = $reader->selectInByIndex(
$indexId,
array(42, 100),
0,
99,
array(new Filter(Comparison::EQUAL, 0, 1))
); this HS query is the same like in SQL: I added one filter with comparison type equal(=), also position is 0 it is position of element inside array filterColumnList when you use getIndexId. I would recommend you to try QueryBuilder, because it is more human friendly :) same query via querybuilder: $selectQueryBuilder = QueryBuilder::select(array('key', 'text'))
->fromDataBase($this->getDatabase())
->fromTable($this->getTableName())
->whereIn('key', array(42, 100))
->andWhere('num', Comparison::EQUAL, 1); another examples you can find in docs or in tests |
Thanks for getting back so quick, appreciate you clearing that up! I gradually started to figure that out, I believe part of the problem was I had fixed composer to 0.1 rather than dev-master so I was working from an older copy and the method hints didn't match up to your examples. ;) Love the look of the querybuilder, very logical and I'm sure a great help to those testing out handlersocket with only a mysql background. I actually wrote part of a sockets library for handlersocket a couple of years ago but it wasn't clean, and I didn't go much beyond basic the basics. The nice thing is that it was abstracted well and the way you've organized your input params falls right in line with what my own library did so your library has been like a drop in replacement for our own, instantly opening up a lot more functionality! Can't tell you how great (and rare) that is! We're doing a lot of throughput through handlersocket, averaging about 50k reads / s, and bursting to 300k / s every 10 min on a regularly run maintenance script. My intention though is to triple that now that I'll have the ability to offload a little more thanks to the work you've done in your library. If I can glean anything important or give back to your library I will. Cheers! |
thx for your feedback Kevin, now I found that packagist set last stable version to 0.04 tag, but it is not a last stable version in fact. I'll double check it. |
Hey Konstantin, I'm having no luck getting results out of the system, and I'm having a hard time reconciling any of the debug output I've come up with. Maybe you can take a quick peak, you'll probably be able to spot something pretty quickly... This is my query object that I pass into my nosql/handlersocket adapter... My Query Object
As you can see above, it contains the basics, index name, the _keymap is in the format of The rest are your own HS objects... Reader
SelectQuery
Here's my current setup after looking through some of your test examples. // Open a connection
$index_id = $this->_read->getIndexId(
$this->_database,
$query->get_table(),
$query->get_index(),
$query->get_fields(),
TRUE,
$filter_keys
);
// Create the select query
/* @var $read SelectQuery */
$read = $this->_read->selectByIndex(
$index_id,
$query->get_type(),
$query->get_key_values(),
$query->get_limit(),
$query->get_offset(),
$filter_values
);
// Get the results as an array
$read->setReturnType(SelectQuery::VECTOR);
// Run the query and parse the results
$data = $read->execute()->getResult()->getData(); No matter what I do Any light you can shed on this would really help! Thanks, |
did u try sent something simple to HS with current configuration without my library? HS worked ok? |
I've been using HS for more than two years in production using our own limited hand crafted library, but wanted to expand it's use, thus the move to your library. Our query object abstracts queries from the adapter so different forms of queries can be dispatched to different adapters depending on the context. For instance, a complex query with joins will automatically go to the Native MySQL adapter, whereas simple Key/Val queries will get routed through HS. All of the queries I'm testing with work in our own HS library, but are coming up with no results through yours. I know it's a simple matter of me injecting something incorrectly which is why I provided the object dumps above. Maybe you can see something missing, or something incorrectly set? Thanks! |
very strange, do u use HS internal auth on servers? // Open a connection
$indexQuery = $reader->getIndexId(
$this->_database,
$query->get_table(),
$query->get_index(),
$query->get_fields(),
false,
$filter_keys
);
$openIndexQueryText = $indexQuery->getQueryString();
// Create the select query
/* @var $read SelectQuery */
$read = $reader->selectByIndex(
1,
$query->get_type(),
$query->get_key_values(),
$query->get_limit(),
$query->get_offset(),
$filter_values
);
$selectQueryText = $read->getQueryString(); I`am interested in $openIndexQueryText and selectQueryText values, dump it here. |
Thanks for the hint on using the query string output, helped me notice my Limit and Offset were reversed, meaning I was limiting to 0 results. :) Now I'm getting an exception out of the
Thanks, |
Haven't made much headway on this, but I do see that the "Driver" does indeed perform encoding/decoding, so not sure where the error is coming from. Here's a sampling of the output from the error....
This is just a snipit but it shows that the error message is cutting in in the middle of my xml result data and a number of Is there an opportunity to output the raw data from the response prior to decoding, and then right after decoding but prior to parsing? |
You can't get response raw text after query with library now, but u can generate plain text from the query and bring it to HS via telnet, because UnknownError is a problem from HS side not from library. |
Sounds like responses getting truncated is the likely cause then. Here's how I previously handled getting responses...
It worked 99% of the time, but there were still some odd issues I hadn't yet sorted out. This will probably help. I'll fork the project and see if I can come up with something based on the stream library you're using (i think). To save a little time, can you point me to file/line where you're performing the actual data read? Thanks, |
Stream library doesn't has any logic, just read/write |
The culprit is actually here where you've hard coded a line length of The PHP docs state the following...
... so it's hitting 1024 bytes received and quitting, truncating the response. I'm not sure you'll be able to get past this using the current function, it looks like it's better suited to retrieving things with a roughly consistent size, which is difficult to count on in all but the most basic scenarios. In the code I posted above, the That means that I'm going to have to change 1024 to something like 512000 (500Kb), to ensure that any eventuality will be dealt with successfully. I'm not sure whether that will have any performance hit or not, because, it will still hit a I'm still working on this and will let you know. Cheers, |
Thought a potential solution may be to use a loop like I provided above but using |
So after an SO question, I've learned that $data = NULL;
while ($buffer = @stream_get_line($streamResource, $this->length, $this->ending)) {
$data .= $buffer;
}
return $data; The only problem is whenever I change the
Maybe you can give this stuff a shot, it's hard for me to debug efficiently without spending a lot more time looking through your stuff. |
It sounds like stream_get_line is too high level for this type of scenario, it will block when there isn't enough data to fill out $limit, and when "/n" has been reached and there's no easy way to detect it because it automatically strips out the EOL. Check out this good description of the problem http://www.linuxonly.nl/docs/41/130_The_problem_with_stream_get_line.html I'm doubtful this is going to be doable without moving over to Sockets. |
I did a lot of tests with fgets, stream_get_contents and stream_get_line.. |
socket_read should be comparable if not faster since it's an extension of the BSD Sockets library, whereas stream_* is a php implementation, so I would consider sockets before the others. That said, you can't test if the data is the same length as the $length setting for the reason outlined in the link above. You don't know if it ended because of $length, or because "\n" was reached (because you can't test for EOL because it's stripped off results automatically), it's impossible to know unless you run one more iteration of the loop which results in the network blocking. |
agree, that's why I count all operation which I send in HS library. |
But it's not the number of lines that we don't know, it's the length of each line. i.e. a simple ID retrieval may only yield 32 bytes, but an XML field could yield 100's of Kb worth of data. They're not always going to be consistent, and unless length is set to a very high number, we will not be able to retrieve the full line. Also due to the nature, the query will take longer to fill data from the buffer before it can test for the EOL when length is set high. Being able to loop over smaller chunks of the data and test for EOL manually will be much faster, but impossible to do with stream_get_line. |
|
That was my assumption as well, but the question then is, why bother building that function with a length parameter at all if you can set it to infinity and have no performance hit? I would bet you that there is a performance decrease the larger that number is. |
I pushed code to |
Thanks Konstantin, I'll pull it down next week and test it out, long weekend here. Cheers! |
Sorry for the long delay in getting back, the new code seems to be working, thank you! I did find a problem with your result parsing, but I've already added a pull request #22 with a patch. I'll put this all through it's paces and let you know if I run into anything else! Cheers! |
no problem, I`m glad that my library helping you! |
So it seemed to start off well under load but within about 3 min I started seeing loads of...
I know the error wasn't coming from the data, the same pages I initially tested which were working well, I retested after I noticed the errors piling up and they were all failing after a short while. Not sure how it overwhelmed things so quickly but there's something going on there. Maybe connection caching or something? I switched back to my own |
It`s hard to say, I would try to look to queries count for send and read |
Do you mean aggregated across the server or read/write per request? |
I mean the values $countQueries and $queryListNotSent inside CommonClient |
Hey, long time! :) I've been testing the library further and everything is running well now, no errors or unexpected results. Works well with large or small data payloads. The only thing I'm finding now is that it's a bit sluggish. When I use my own lightweight handlersocket reader, I'm able to load a specific page that is heavily HS reliant, and I can get it up consistently in 1.8s - 1.9s, but when I switch the adapter to yours, it's taking 4s+. I'll have to do more testing, but is there anything you know of that I can switch off, that's on by default that might add a lot of overhead? |
@oucil Can you consider open-sourcing your query object or parts of it? Queries abstraction way sounds cool. If it is 2x faster than HandlerSocketLibrary, your code is definitely worth testing. |
First of Konstantin, thank you for writing your own bike :)
I have a question about the "Filter" object, specifically the "position" parameter. I'm not clear what that is. The method describes the type as an int, but I'm not sure what the int is in reference to. Is it a reference to the array position of a corresponding field from the parent select statement?
Appreciate your insights!
Kevin.
The text was updated successfully, but these errors were encountered: