Comments (1)
hi @zopyx
what's happening in your code is that every commit requests a request, resulting in 100k requests.
you can speed up the process by doing bulk inserts. this is achieved by doing multiple adds on the same session before committing.
I've adopted your example:
import time
from datetime import datetime
import sqlalchemy as sa
from sqlalchemy import func, desc
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from crate.client import connect
from crate.client.sqlalchemy.types import Object
from crate.client.exceptions import ProgrammingError
hosts = ['localhost:4200']
engine = sa.create_engine('crate://', connect_args={'servers': hosts})
Base = declarative_base()
Session = sessionmaker(engine)
session = Session()
conn = connect(hosts)
cursor = conn.cursor()
try:
cursor.execute('''DROP TABLE foo2''')
except ProgrammingError:
pass
cursor.execute('''CREATE TABLE foo2 (user_id string primary key, created_at timestamp)''')
class Foo2(Base):
__tablename__ = 'foo2'
user_id = sa.Column(sa.String, primary_key=True)
created_at = sa.Column(sa.DateTime)
def __repr__(self):
return '<Tweet {0}>'.format(self.user_id)
ts = time.time()
for i in range(100000):
f = Foo2(user_id=i, created_at=datetime.now())
session.add(f)
if i % 10000 == 0:
print(i)
if i % 1000 == 0:
session.commit()
print time.time() - ts
print 'done'
This one is approx twice as fast (65.69s
) as your original example (125.51s
).
You can still play around how many records you insert per bulk. Also note that the number of configured replicas and shards do have impact on insert times.
If you want even faster import times you should consider using the Python client directly.
e.g.
cursor.execute("""INSERT INTO foo2 (user_id, created_at) VALUES (?,?), (?, ?) ...""", [...])
see docs: https://crate.io/docs/projects/crate-python/en/latest/client.html#inserting-data
Hope this helps!
Christian
from crate.
Related Issues (20)
- User session stays active after user is dropped when using SET SESSION AUTHORIZATION with superuser HOT 2
- Introduce a timeout for the Parsing/Analysis stage HOT 3
- Add role session setting defaults HOT 1
- Add support to work with FDW in Postgres compatible tools (e.g. DBeaver) HOT 1
- Can't read object, timestamp, geopoint fields from remote CrateDB cluster using FDW HOT 1
- Allow FDW user mapping against roles HOT 3
- Allow the use of EXPLAIN ANALYZE on queries with scalar subselects
- Ensure own password is also hidden when querying `information_schema.user_mapping_options` HOT 2
- SQLParseException on query with subqueries with latest nightly HOT 4
- FDW - Cannot read JSONB directly from PostgreSQL Server HOT 2
- Expand `OBJECT`s during view creation to include subfields in metadata HOT 4
- ClassCastException on function with RETURNS OBJECT HOT 2
- Support `ALTER SERVER` to change connection url
- Support PUBLIC user mapping for FDW HOT 1
- Unexpected result when using `PG_GET_PARTKEYDEF` HOT 1
- Unexpected result when using `DEFAULT` during creating table HOT 1
- Regression on correlated subqueries
- Meta - Foreign Tables with PostgreSQL JSON(B) Columns HOT 5
- Can't join foreign table with a local table in a multi-node cluster HOT 1
- INSERT INTO much slower than separate SELECT and INSERT
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 crate.