Comments (7)
@imtrobin ArangoDatabase
is not meant to be ThreadSafe
, you should create new instance for each request(or few request)
-
ArangoDatabase
is responsible for change tracking, so if you create only one instance. its change tracking store will become bigger and bigger -
creating
ArangoDatabase
instance is a cheap operation. no client/db initialization will happen
from arangoclient.net.
@imtrobin why ChangeSetting/FindSetting
is not thread safe?
from arangoclient.net.
I saw your other thread, that the advice is to keep disposing and recreating new instance. I dug briefly in the code, I see your have one static httpclient shared among all db connection, so I think that is good?
FindSetting is used in ArangoDatabase.CreateWithSetting, and it should lock when it is tryin to get/add to cacheSettings, no?
from arangoclient.net.
@imtrobin for each httpclient instance an underlying tcp connection will be used, therefore if we use multiple httpclient instance then multiple tcp handshake will happen for creating new tcp connection. so i think have an httpclient for all requests make sense.
if multiple thread invoke TryAdd
with the same key, one of them will succeed and other fails(no exception thrown), i dont think using lock would bring any thread safety here.
from arangoclient.net.
yes, one httpclient is correct way to avoid socket exhaustion. Though I think it does not work as well for multiple arangodb servers, but I think that's not your design here, right?
The multiple thread problem is with Try/Get, another guy can enter before TryAdd is complete.
static DatabaseSharedSetting FindSetting(string identifier, bool? throwIfNotFound = false)
{
if (string.IsNullOrWhiteSpace(identifier))
throw new ArgumentNullException("Setting identifier");
DatabaseSharedSetting setting = null;
if (!cachedSettings.TryGetValue(identifier, out setting))
{
// SECOND COMES COMES HERE BEFORE TRYADD
if (throwIfNotFound == true)
throw new InvalidOperationException(string.Format("Can not find database setting identifier '{0}'", identifier));
// FIRST GUY COMES THROUGH HERE
setting = new DatabaseSharedSetting();
setting.SettingIdentifier = identifier;
cachedSettings.TryAdd(identifier, setting);
}
return setting;
}
from arangoclient.net.
@imtrobin i think one http client could also works for multiple enpoints(performance wise) https://stackoverflow.com/a/39733434
but having a http client for each arangodb server is a good idea , since it could benefit from having separate configs which could be only set once for all requests(like proxy).
if first and second guy trying to add different identifier
as keys, then there is no problem. but if they add same identifier
as key, then first guy will succeed and the second one will fail with no exception thrown. is it not acceptable?
from arangoclient.net.
The FindSetting is used in other places, so if those two calls are generated at the same time (by serverless architecture), then the second call gets a different instance of DatabaseSharedSetting instead of the instance in the cachedSettings. By logic, I would assume I would get the same instance in memory. Although the code doesn't break, but it's sure hard while debugging cos the memory instance are different which is not obvious. Imagine if I kept both returned instances and do other stuff, oh boy.
from arangoclient.net.
Related Issues (20)
- ArangoServerException not throw when db unavailable HOT 2
- Confused with SystemDatabaseCredential HOT 5
- Custom Index HOT 6
- ByExampleAsync missing HOT 2
- Make ChangeCollectionPropertyForType public HOT 1
- Using LINQ query with Where performance HOT 1
- Error in generated AQL when upserting a generic document HOT 7
- ArangoServerException eats up all the useful information like status code and error number HOT 2
- Make collection name resolver more extensible HOT 2
- Annotating a property of type Guid as DocumentProperty.Key throws InvalidCastException HOT 2
- Support private setter
- CreateStatement<object> & Remove Vertex HOT 1
- Ternary operator support
- Global error handling policy
- Support for keyOptions: uuid
- Edge Document API not supported?
- Cannot Simply Connect to Server...... HOT 2
- Secure connection to ArangoDB
- Query directly within a collection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arangoclient.net.